rocketfuel_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +60 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +5 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +13 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +60 -0
  10. data/Rakefile +9 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/rocketfuel_api.rb +24 -0
  14. data/lib/rocketfuel_api/connection.rb +20 -0
  15. data/lib/rocketfuel_api/error.rb +17 -0
  16. data/lib/rocketfuel_api/faraday/raise_http_error.rb +36 -0
  17. data/lib/rocketfuel_api/resource.rb +41 -0
  18. data/lib/rocketfuel_api/resource/advertisement_ad_assignment.rb +4 -0
  19. data/lib/rocketfuel_api/resource/advertisement_card.rb +4 -0
  20. data/lib/rocketfuel_api/resource/assigned_flight.rb +4 -0
  21. data/lib/rocketfuel_api/resource/campaign.rb +4 -0
  22. data/lib/rocketfuel_api/resource/campaign_pixel.rb +4 -0
  23. data/lib/rocketfuel_api/resource/company.rb +4 -0
  24. data/lib/rocketfuel_api/resource/flight.rb +4 -0
  25. data/lib/rocketfuel_api/resource/line_item.rb +4 -0
  26. data/lib/rocketfuel_api/resource/pixel.rb +4 -0
  27. data/lib/rocketfuel_api/resource/pixel_search.rb +4 -0
  28. data/lib/rocketfuel_api/resource/reporting.rb +4 -0
  29. data/lib/rocketfuel_api/resource/reporting_dimension.rb +4 -0
  30. data/lib/rocketfuel_api/resource/reporting_metric.rb +4 -0
  31. data/lib/rocketfuel_api/resource/sub_network.rb +4 -0
  32. data/lib/rocketfuel_api/resource/tactic.rb +4 -0
  33. data/lib/rocketfuel_api/resource/third_party_pixel_search.rb +4 -0
  34. data/lib/rocketfuel_api/service.rb +84 -0
  35. data/lib/rocketfuel_api/service/advertisement_ad_assignment.rb +13 -0
  36. data/lib/rocketfuel_api/service/advertisement_card.rb +13 -0
  37. data/lib/rocketfuel_api/service/assigned_flight.rb +13 -0
  38. data/lib/rocketfuel_api/service/campaign.rb +13 -0
  39. data/lib/rocketfuel_api/service/campaign_pixel.rb +13 -0
  40. data/lib/rocketfuel_api/service/company.rb +13 -0
  41. data/lib/rocketfuel_api/service/flight.rb +13 -0
  42. data/lib/rocketfuel_api/service/line_item.rb +13 -0
  43. data/lib/rocketfuel_api/service/pixel.rb +13 -0
  44. data/lib/rocketfuel_api/service/pixel_search.rb +13 -0
  45. data/lib/rocketfuel_api/service/reporting.rb +13 -0
  46. data/lib/rocketfuel_api/service/reporting_dimension.rb +13 -0
  47. data/lib/rocketfuel_api/service/reporting_metric.rb +13 -0
  48. data/lib/rocketfuel_api/service/sub_network.rb +13 -0
  49. data/lib/rocketfuel_api/service/tactic.rb +13 -0
  50. data/lib/rocketfuel_api/service/third_party_pixel_search.rb +13 -0
  51. data/lib/rocketfuel_api/version.rb +5 -0
  52. data/rocketfuel_api.gemspec +35 -0
  53. metadata +193 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3f80b8c0cb87bfc7b2ca8e56b0f3633c2e6d4b1
4
+ data.tar.gz: cba6fa8c1d68dced78de90cfc84379fe3ad1f145
5
+ SHA512:
6
+ metadata.gz: 6a84713eadb4240f663b5ca36a5b47fd61179b7fbcf52ef8da59729bf38647fe28f55bee5521bfd867228289f421e3b03dd6f4cfec0722cfc3b1b49399e401d4
7
+ data.tar.gz: 429ab98ae6ac58122fc204df377903d57c0279f159c88fbb75ecc67d54d2138b723058b0c51d024c37504975175f78c071eadfb3caf7af1450ed9f9cd471ed0a
@@ -0,0 +1,60 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.1-node-browsers
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.6
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-gems
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
33
+
34
+ - save_cache:
35
+ paths:
36
+ - ./vendor/bundle
37
+ key: v1-dependencies-gems
38
+
39
+ # Database setup
40
+ # - run: bundle exec rake create_test_db
41
+
42
+ # run tests!
43
+ - run:
44
+ name: run tests
45
+ command: |
46
+ mkdir /tmp/test-results
47
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
48
+
49
+ bundle exec rspec --format progress \
50
+ --format RspecJunitFormatter \
51
+ --out /tmp/test-results/rspec.xml \
52
+ --format progress \
53
+ ${TEST_FILES}
54
+
55
+ # collect reports
56
+ - store_test_results:
57
+ path: /tmp/test-results
58
+ - store_artifacts:
59
+ path: /tmp/test-results
60
+ destination: test-results
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ before_install: gem install bundler -v 1.15.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at stefan.greffenius@ad2games.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in rocketfuel_api.gemspec
8
+ gemspec
9
+
10
+ group :development, :test do
11
+ gem 'rspec_junit_formatter', '0.2.2'
12
+ gem 'rubocop-ci', github: 'ad2games/rubocop-ci'
13
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Stefan Greffenius
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ # RocketfuelApi [![CircleCI](https://circleci.com/gh/ad2games/rocketfuel_api.svg?style=svg)](https://circleci.com/gh/ad2games/rocketfuel_api)
2
+
3
+ Client library for [Rocketfuel API](https://api.rocketfuel.com)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rocketfuel_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rocketfuel_api
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ # for development/specs (the default uri is: https://api-sandbox.rocketfuel.com/2016)
25
+ connection = RocketfuelApi::Connection.new(
26
+ auth_token: ENV['ROCKETFUEL_API_SANDBOX_AUTH_TOKEN']
27
+ )
28
+
29
+ # for production
30
+ connection = RocketfuelApi::Connection.new(
31
+ uri: 'https://api.rocketfuel.com/2016'
32
+ auth_token: ENV['ROCKETFUEL_API_AUTH_TOKEN']
33
+ )
34
+
35
+ service = RocketfuelApi::Service::Company.new(connection)
36
+ service.get(10) # returns the company with the ID 10
37
+ service.get_all # returns all companies
38
+ ```
39
+
40
+ Also the `spec/integration` directory contains examples.
41
+
42
+ Note: Only the `Company` Service `GET` requests are tested so far.
43
+
44
+ ## Development
45
+
46
+ To be able to run the specs, the env var `ROCKETFUEL_API_SANDBOX_AUTH_TOKEN` is needed.
47
+
48
+ We run rake rubocop to make sure, everything looks good.
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
53
+
54
+ ## Code of Conduct
55
+
56
+ Everyone interacting in the RocketfuelApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rocketfuel_api/blob/master/CODE_OF_CONDUCT.md).
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ad2games/rocketfuel_api.
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop-ci'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rocketfuel_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday_middleware'
4
+
5
+ require 'rocketfuel_api/error'
6
+ require 'rocketfuel_api/faraday/raise_http_error'
7
+
8
+ require 'rocketfuel_api/connection'
9
+ require 'rocketfuel_api/service'
10
+ require 'rocketfuel_api/resource'
11
+ require 'rocketfuel_api/version'
12
+
13
+ module RocketfuelApi
14
+ AUTOLOAD_PATHS = [
15
+ Dir[File.dirname(__dir__) + '/lib/rocketfuel_api/resource/*.rb'],
16
+ Dir[File.dirname(__dir__) + '/lib/rocketfuel_api/service/*.rb']
17
+ ].flatten.freeze
18
+
19
+ def self.root
20
+ Pathname.new(File.dirname(__dir__))
21
+ end
22
+
23
+ AUTOLOAD_PATHS.each { |file| require file }
24
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Connection
4
+ def initialize(config)
5
+ @config = config
6
+ @config[:uri] ||= 'https://api-sandbox.rocketfuel.com/2016'
7
+
8
+ @connection = Faraday.new(@config[:uri]) do |conn|
9
+ conn.request :json
10
+ conn.response :json, content_type: /\bjson$/
11
+ conn.use RocketfuelApi::Faraday::Response::RaiseHttpError
12
+ conn.adapter Faraday.default_adapter
13
+ conn.headers['X-Auth-Token'] = @config[:auth_token]
14
+ end
15
+ end
16
+
17
+ def get(uri_suffix, params = {})
18
+ @connection.get(uri_suffix, params)
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RocketfuelApi
4
+ class Error < StandardError; end
5
+ class BadRequest < Error; end
6
+ class Unauthorized < Error; end
7
+ class Forbidden < Error; end
8
+ class NotFound < Error; end
9
+ class NotAcceptable < Error; end
10
+ class UnprocessableEntity < Error; end
11
+ class InternalServerError < Error; end
12
+ class NotImplemented < Error; end
13
+ class BadGateway < Error; end
14
+ class ServiceUnavailable < Error; end
15
+ class InvalidJson < Error; end
16
+ class Timeout < Error; end
17
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RocketfuelApi
4
+ module Faraday
5
+ module Response
6
+ class RaiseHttpError < ::Faraday::Response::Middleware
7
+ EXCEPTIONS = {
8
+ 400 => RocketfuelApi::BadRequest,
9
+ 401 => RocketfuelApi::Unauthorized,
10
+ 403 => RocketfuelApi::Forbidden,
11
+ 404 => RocketfuelApi::NotFound,
12
+ 406 => RocketfuelApi::NotAcceptable,
13
+ 422 => RocketfuelApi::UnprocessableEntity,
14
+ 500 => RocketfuelApi::InternalServerError,
15
+ 501 => RocketfuelApi::NotImplemented,
16
+ 502 => RocketfuelApi::BadGateway,
17
+ 503 => RocketfuelApi::ServiceUnavailable
18
+ }.freeze
19
+
20
+ def on_complete(response)
21
+ http_status = response.status.to_i
22
+
23
+ return if http_status == 200
24
+
25
+ exception = EXCEPTIONS.fetch(http_status)
26
+
27
+ raise exception, response.body
28
+ end
29
+
30
+ def error_message(response)
31
+ "#{response.method.to_s.upcase} #{response.url}: #{response.status} - #{response.body}"
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource
4
+ def initialize(json, service)
5
+ @json = json
6
+ @service = service
7
+ end
8
+
9
+ def update(route_params = {}, body_params = {})
10
+ resource = @service.update(id, route_params, body_params)
11
+ @json = resource.raw_json
12
+
13
+ self
14
+ end
15
+
16
+ def delete(route_params = {})
17
+ @service.delete(id, route_params)
18
+ end
19
+
20
+ def raw_json
21
+ @json
22
+ end
23
+
24
+ def method_missing(sym, *args, &block)
25
+ if @json.respond_to?(sym)
26
+ @json.public_send(sym, *args, &block)
27
+ elsif @json.key?(sym.to_s)
28
+ @json[sym.to_s]
29
+ else
30
+ super
31
+ end
32
+ end
33
+
34
+ def respond_to_missing?(method_name, include_private = false)
35
+ @json.respond_to?(sym) || @json.key?(sym.to_s) || super
36
+ end
37
+
38
+ def to_s
39
+ @json.inspect
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::AdvertisementAdAssignment < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::AdvertisementCard < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::AssignedFlight < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::Campaign < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::CampaignPixel < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::Company < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::Flight < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::LineItem < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::Pixel < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::PixelSearch < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::Reporting < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::ReportingDimension < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::ReportingMetric < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::SubNetwork < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::Tactic < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Resource::ThirdPartyPixelSearch < RocketfuelApi::Resource
4
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @connection = connection
6
+ end
7
+
8
+ def resource_class
9
+ @resource_class ||= begin
10
+ resource_name = name.capitalize.gsub(/(_(.))/) { |_c| Regexp.last_match(2).upcase }
11
+ RocketfuelApi::Resource.const_get(resource_name)
12
+ end
13
+ end
14
+
15
+ def name
16
+ @name ||= begin
17
+ str = self.class.name.split('::').last
18
+ str.gsub(/(.)([A-Z])/, '\1_\2').downcase
19
+ end
20
+ end
21
+
22
+ def plural_name
23
+ name + 's'
24
+ end
25
+
26
+ def uri_suffix
27
+ plural_name
28
+ end
29
+
30
+ def get(id, params = {})
31
+ params = params.merge("#{name}_id" => id)
32
+
33
+ response = @connection.get(uri_suffix, params).body
34
+
35
+ parse_response(response)
36
+ end
37
+
38
+ def get_all(params = {})
39
+ response = @connection.get(uri_suffix, params).body
40
+
41
+ parse_response(response)
42
+ end
43
+
44
+ def create(route_params = {}, body = {})
45
+ raise(RocketfuelApi::NotImplemented, 'Service is read-only.') if @read_only
46
+
47
+ body = { uri_name => body }
48
+ route = @connection.build_url(uri_suffix, route_params)
49
+ response = @connection.post(route, body)
50
+
51
+ if response.status != 200
52
+ raise RocketfuelApi::BadRequest, response.inspect
53
+ end
54
+
55
+ parse_response(response.body)
56
+ end
57
+
58
+ def update(id, route_params = {}, body = {})
59
+ raise(AppnexusApi::NotImplemented, 'Service is read-only.') if @read_only
60
+
61
+ body = { uri_name => body }
62
+ route = @connection.build_url(uri_suffix, route_params.merge('id' => id))
63
+ response = @connection.put(route, body)
64
+
65
+ if response.status != 200
66
+ raise RocketfuelApi::BadRequest, response.inspect
67
+ end
68
+
69
+ parse_response(response.body)
70
+ end
71
+
72
+ def parse_response(response)
73
+ case response
74
+ when Array
75
+ response.map do |json|
76
+ resource_class.new(json, self)
77
+ end
78
+ when Hash
79
+ resource_class.new(response, self)
80
+ else
81
+ raise format("Can't parse response, it's a %s", response.class)
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::AdvertisementAdAssignment < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'ads/ad_assignments'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::AdvertisementCard < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'ads/cards'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::AssignedFlight < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'assigned_flights'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::Campaign < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'campaigns'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::CampaignPixel < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'campaigns/pixels'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::Company < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'companies'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::Flight < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'flights'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::LineItem < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'line_items'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::Pixel < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'pixels'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::PixelSearch < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'pixels/search'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::Reporting < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'reports'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::ReportingDimension < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'reports/dimensions'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::ReportingMetric < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'reports/metrics'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::SubNetwork < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'sub_networks'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::Tactic < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'tactics'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RocketfuelApi::Service::ThridPartyPixelSearch < RocketfuelApi::Service
4
+ def initialize(connection)
5
+ @read_only = true
6
+
7
+ super(connection)
8
+ end
9
+
10
+ def uri_suffix
11
+ 'thrid_party_pixels/search'
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RocketfuelApi
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'rocketfuel_api/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'rocketfuel_api'
10
+ spec.version = RocketfuelApi::VERSION
11
+ spec.authors = ['Stefan Greffenius']
12
+ spec.email = ['stefan.greffenius@ad2games.com']
13
+
14
+ spec.summary = 'Rocketfuel API Client.'
15
+ spec.description = 'Rocketfuel API Client.'
16
+ spec.homepage = 'https://www.rocketfuel.com'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_dependency 'faraday'
27
+ spec.add_dependency 'faraday_middleware'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.15'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+
33
+ spec.add_development_dependency 'vcr'
34
+ spec.add_development_dependency 'webmock'
35
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rocketfuel_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Stefan Greffenius
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Rocketfuel API Client.
112
+ email:
113
+ - stefan.greffenius@ad2games.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".circleci/config.yml"
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - lib/rocketfuel_api.rb
130
+ - lib/rocketfuel_api/connection.rb
131
+ - lib/rocketfuel_api/error.rb
132
+ - lib/rocketfuel_api/faraday/raise_http_error.rb
133
+ - lib/rocketfuel_api/resource.rb
134
+ - lib/rocketfuel_api/resource/advertisement_ad_assignment.rb
135
+ - lib/rocketfuel_api/resource/advertisement_card.rb
136
+ - lib/rocketfuel_api/resource/assigned_flight.rb
137
+ - lib/rocketfuel_api/resource/campaign.rb
138
+ - lib/rocketfuel_api/resource/campaign_pixel.rb
139
+ - lib/rocketfuel_api/resource/company.rb
140
+ - lib/rocketfuel_api/resource/flight.rb
141
+ - lib/rocketfuel_api/resource/line_item.rb
142
+ - lib/rocketfuel_api/resource/pixel.rb
143
+ - lib/rocketfuel_api/resource/pixel_search.rb
144
+ - lib/rocketfuel_api/resource/reporting.rb
145
+ - lib/rocketfuel_api/resource/reporting_dimension.rb
146
+ - lib/rocketfuel_api/resource/reporting_metric.rb
147
+ - lib/rocketfuel_api/resource/sub_network.rb
148
+ - lib/rocketfuel_api/resource/tactic.rb
149
+ - lib/rocketfuel_api/resource/third_party_pixel_search.rb
150
+ - lib/rocketfuel_api/service.rb
151
+ - lib/rocketfuel_api/service/advertisement_ad_assignment.rb
152
+ - lib/rocketfuel_api/service/advertisement_card.rb
153
+ - lib/rocketfuel_api/service/assigned_flight.rb
154
+ - lib/rocketfuel_api/service/campaign.rb
155
+ - lib/rocketfuel_api/service/campaign_pixel.rb
156
+ - lib/rocketfuel_api/service/company.rb
157
+ - lib/rocketfuel_api/service/flight.rb
158
+ - lib/rocketfuel_api/service/line_item.rb
159
+ - lib/rocketfuel_api/service/pixel.rb
160
+ - lib/rocketfuel_api/service/pixel_search.rb
161
+ - lib/rocketfuel_api/service/reporting.rb
162
+ - lib/rocketfuel_api/service/reporting_dimension.rb
163
+ - lib/rocketfuel_api/service/reporting_metric.rb
164
+ - lib/rocketfuel_api/service/sub_network.rb
165
+ - lib/rocketfuel_api/service/tactic.rb
166
+ - lib/rocketfuel_api/service/third_party_pixel_search.rb
167
+ - lib/rocketfuel_api/version.rb
168
+ - rocketfuel_api.gemspec
169
+ homepage: https://www.rocketfuel.com
170
+ licenses:
171
+ - MIT
172
+ metadata: {}
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.6.11
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: Rocketfuel API Client.
193
+ test_files: []