0.0
No commit activity in last 3 years
No release in over 3 years
Ruby client for myTarget API. It takes care of JSON parsing, file parameters, nested resources, api versions. OneRetarget.com - advertising automation service
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.1, >= 2.1.4
~> 12.3.0, >= 12.3.0
~> 3.7.0, >= 3.7.0
~> 0.89.1
~> 2.3.2, >= 2.3.2

Runtime

~> 2.0, >= 2.0.0
~> 2.0, >= 2.0.0
 Project Readme

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

Name Default value Description
:v 1 API version
:logger An object to log requests and exceptions. The object must respond to << method
:headers Headers 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

Name Default value Description
:id Resource ID. Optional for Read, required for Update and Delete
:id_param_key :id Option 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
Name Description
MyTargetApi::RequestError Request didn't succeed

Testing

bundle exec rspec

Contributing

Create a pull-request or make an issue