Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

my_target_api

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

my_target_api

  • 2.0.9
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Ruby client for myTarget API

Build Status Maintainability

Installation

Add this line to your application's Gemfile:

gem 'my_target_api', '~> 2.0.9'

Or install from command line:

$ gem install my_target_api

Usage

Initialization

# You need an access token to use API
my_target_api = MyTargetApi.new(access_token)

Resources

# Root resources
campaigns_resource = my_target_api.resource('campaigns')
remarketing_resource = my_target_api.resource('remarketing', v: 2)

# Nested resources
remarketing_counters_resource = my_target_api.resource('remarketing/counters', v: 2)
remarketing_counters_resource = remarketing_resource.resource('counters')
Options
NameDefault valueDescription
:v1API version
:loggerAn object to log requests and exceptions. The object must respond to << method
:headersHeaders hash to pass with request

Create, Read, Update, Delete

remarketing_counters_resource.create(counter_id: 121212) # => [{ 'id' => 343434 }]

campaigns_resource.read # => [{ 'id' => 12345, ... }, { ... }]

campaigns_resource.read(id: 12345) # => [{ 'id' => 12345, ... }]

campaigns_resource.update(id: 12345, status: 'blocked') # => [{ 'id' => 12345, 'status' => 'blocked' }]

remarketing_counters_resource.delete(id: 343434) # => [{ 'success' => true }]
Options
NameDefault valueDescription
:idResource ID. Optional for Read, required for Update and Delete
:id_param_key:idOption key for resource ID

Changing default ID param name

campaigns_resource.read(id_key_param: :campaign_id, campaign_id: 12345) # => [{ 'id' => 12345, ... }]

File upload

static_resource = my_target_api.resource('content/static', v: 2)
picture = File.new('path/to/picture.jpg', 'rb')

static_resource.create(file: picture, data: { width: 1200, height: 800 })

Raw data upload

search_phrases_resource = my_target_api.resource('search_phrases', v: 2)
phrases = "phrase\nfirst phrase\nsecond phrase\n"

search_phrases_resource.upload(phrases, name: 'search phrases list')

Exceptions

def read_active_campaigns

  campaigns_resource.read(status: 'active')

rescue MyTargetApi::RequestError => e

  puts e.message, e.method, e.url, e.params, e.request_body, e.response, e.backtrace
  # You can access the original exception
  puts e.original_exception&.message, e.original_exception&.backtrace

end
NameDescription
MyTargetApi::RequestErrorRequest didn't succeed

Testing

bundle exec rspec

Contributing

Create a pull-request or make an issue

FAQs

Package last updated on 01 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc