Giter VIP home page Giter VIP logo

appnexusapi's Introduction

Appnexus API Wrapper

An unofficial Ruby API Wrapper for the Appnexus Service Console APIs.

If you use the Appnexus Service Impression Bus API's, you may be more interested in this project: https://github.com/simplifi/appnexusapi-impbus

Installation

Add this line to your application's Gemfile:

gem 'appnexusapi'

And then execute:

$ bundle

Or install it yourself as:

$ gem install appnexusapi

Usage

Configure defaults

AppnexusApi.configure do |config|
  config.logger = Logger.new('/path/to/log.log')
end

Establish a connection:

connection = AppnexusApi::Connection.new(
  'username' => 'username',
  'password' => 'password',
  'logger'   => Logger.new(STDOUT) # defaults to STDOUT

  # Defaults to connecting to https://api.appnexus.com/ but you can optionally pass a uri to
  # connect to another endpoint, e.g. the staging site could be
  # "uri" => 'http://api-test.appnexus.com',
)

Use a Service:

member_service = AppnexusApi::MemberService.new(connection)
# get always returns an array of results
# and defaults "num_elements" to 100 and "start_element" to 0
# and returns an AppnexusApi::Resource object which is a wrapper around the JSON
member = member_service.get.first

line_item_service = AppnexusApi::LineItemService.new(connection)
line_item = line_item_service.get.first
line_item = line_item_service.get({advertiser_id: 12345}).first

# create a new object
url_params  = { advertiser_id: 12345 }
body_params = { name: "some line item", code: "line item code"}

line_item = line_item_service.create(url_params, body_params)
line_item.state


# update an object
update_params = { state: "inactive" }
json_result = line_item.update(url_params, update_params)

# delete an object
line_item.delete(url_params)

# save an object that you modified locally
line_item.raw_json[:state] = 'active'
line_item.save

# this raises an AppnexusApi::UnprocessableEntity, not a 404 as it should
line_item_service.get(line_item.id)

new_creative = {
  "content"   => "<iframe src='helloword.html'></iframe>",
  "width" => "300",
  "height" => "250",
  "template"  =>{ "id" => 7 }
}
creative = creative_service.create(new_creative)
creative.update("campaign" => "Testing")

Downloading Log Level Data:

download_service = AppnexusApi::LogLevelDataService.new(
  connection,
  downloaded_files_path: '/example/local/path',
  siphon_name: 'standard_feed'
)

downloaded_files = data_service.download_new_files_since('2016-02-01'.to_time)

Testing

Running Existing Specs

bundle exec rspec

Writing New Specs or Updating Old Ones

This library uses VCR and Webmock to record API call HTTP data and play it back when you run the specs. To write new specs or update old ones, however, you will need to actually provide a valid login/password in a .env file (see env_example for an example) before launching the specs.

To update a spec, simply remove the relevant file from spec/fixtures/vcr (and setup the username/password as above) before launching rspec; the changes will be recorded automatically by VCR.

Debugging

To trigger full Faraday request/respone logging, set the APPNEXUS_API_DEBUG environment variable before launching your application

export APPNEXUS_API_DEBUG=true

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make changes (with tests -- at least integration tests, please)
  4. Commit your changes (git commit -am 'Added some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

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.