Git Product home page Git Product logo

my_target_api's Introduction

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

my_target_api's People

Contributors

anime-memes avatar gvalentiny avatar resivalex avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.