appnexusapi 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +71 -39
  4. data/appnexusapi.gemspec +1 -2
  5. data/lib/appnexusapi.rb +21 -10
  6. data/lib/appnexusapi/configuration.rb +12 -0
  7. data/lib/appnexusapi/connection.rb +83 -90
  8. data/lib/appnexusapi/error.rb +3 -0
  9. data/lib/appnexusapi/faraday/raise_http_error.rb +15 -1
  10. data/lib/appnexusapi/read_only_service.rb +8 -0
  11. data/lib/appnexusapi/resource.rb +19 -15
  12. data/lib/appnexusapi/service.rb +35 -48
  13. data/lib/appnexusapi/services/ad_server_service.rb +9 -0
  14. data/lib/appnexusapi/{advertiser_service.rb → services/advertiser_service.rb} +0 -0
  15. data/lib/appnexusapi/{bidder_instance_service.rb → services/bidder_instance_service.rb} +0 -6
  16. data/lib/appnexusapi/{bidder_profile_service.rb → services/bidder_profile_service.rb} +0 -6
  17. data/lib/appnexusapi/{bidder_service.rb → services/bidder_service.rb} +0 -0
  18. data/lib/appnexusapi/services/brand_service.rb +2 -0
  19. data/lib/appnexusapi/services/browser_service.rb +2 -0
  20. data/lib/appnexusapi/{campaign_service.rb → services/campaign_service.rb} +0 -0
  21. data/lib/appnexusapi/services/category_service.rb +5 -0
  22. data/lib/appnexusapi/{content_category_service.rb → services/content_category_service.rb} +0 -1
  23. data/lib/appnexusapi/{creative_service.rb → services/creative_service.rb} +0 -0
  24. data/lib/appnexusapi/{creative_template_service.rb → services/creative_template_service.rb} +1 -6
  25. data/lib/appnexusapi/services/device_model_service.rb +2 -0
  26. data/lib/appnexusapi/{domain_list_service.rb → services/domain_list_service.rb} +0 -0
  27. data/lib/appnexusapi/services/inventory_attribute_service.rb +2 -0
  28. data/lib/appnexusapi/{inventory_source_service.rb → services/inventory_source_service.rb} +0 -0
  29. data/lib/appnexusapi/services/language_service.rb +2 -0
  30. data/lib/appnexusapi/{line_item_service.rb → services/line_item_service.rb} +0 -0
  31. data/lib/appnexusapi/services/log_level_data_download_service.rb +13 -0
  32. data/lib/appnexusapi/services/log_level_data_service.rb +105 -0
  33. data/lib/appnexusapi/services/media_type_service.rb +2 -0
  34. data/lib/appnexusapi/{member_service.rb → services/member_service.rb} +0 -0
  35. data/lib/appnexusapi/{object_limit_service.rb → services/object_limit_service.rb} +0 -0
  36. data/lib/appnexusapi/{operating_system_extended_service.rb → services/operating_system_extended_service.rb} +1 -6
  37. data/lib/appnexusapi/services/operating_system_service.rb +2 -0
  38. data/lib/appnexusapi/{payment_rule_service.rb → services/payment_rule_service.rb} +0 -0
  39. data/lib/appnexusapi/{placement_service.rb → services/placement_service.rb} +0 -0
  40. data/lib/appnexusapi/services/platform_member_service.rb +2 -0
  41. data/lib/appnexusapi/{profile_service.rb → services/profile_service.rb} +0 -0
  42. data/lib/appnexusapi/{publisher_service.rb → services/publisher_service.rb} +0 -0
  43. data/lib/appnexusapi/{segment_service.rb → services/segment_service.rb} +0 -2
  44. data/lib/appnexusapi/{site_service.rb → services/site_service.rb} +0 -0
  45. data/lib/appnexusapi/services/technical_attribute_service.rb +2 -0
  46. data/lib/appnexusapi/{tiny_tag_service.rb → services/tiny_tag_service.rb} +0 -6
  47. data/lib/appnexusapi/{user_service.rb → services/user_service.rb} +0 -0
  48. data/lib/appnexusapi/version.rb +1 -1
  49. data/spec/connection_spec.rb +46 -10
  50. data/spec/fixtures/vcr/content_category_crud.yml +188 -69
  51. data/spec/fixtures/vcr/log_level_data_service_download.yml +213 -0
  52. data/spec/integration/content_category_spec.rb +4 -0
  53. data/spec/{creative_service_spec.rb → integration/creative_service_spec.rb} +0 -0
  54. data/spec/integration/log_level_data_service_spec.rb +13 -0
  55. data/spec/{object_limit_service_spec.rb → integration/object_limit_service_spec.rb} +0 -0
  56. data/spec/integration/placement_spec.rb +0 -1
  57. data/spec/spec_helper.rb +2 -3
  58. metadata +52 -94
  59. data/lib/appnexusapi/ad_server_resource.rb +0 -2
  60. data/lib/appnexusapi/ad_server_service.rb +0 -20
  61. data/lib/appnexusapi/advertiser_resource.rb +0 -2
  62. data/lib/appnexusapi/bidder_instance_resource.rb +0 -2
  63. data/lib/appnexusapi/bidder_profile_resource.rb +0 -2
  64. data/lib/appnexusapi/bidder_resource.rb +0 -2
  65. data/lib/appnexusapi/brand_resource.rb +0 -2
  66. data/lib/appnexusapi/brand_service.rb +0 -8
  67. data/lib/appnexusapi/browser_resource.rb +0 -2
  68. data/lib/appnexusapi/browser_service.rb +0 -8
  69. data/lib/appnexusapi/campaign_resource.rb +0 -2
  70. data/lib/appnexusapi/category_resource.rb +0 -2
  71. data/lib/appnexusapi/category_service.rb +0 -12
  72. data/lib/appnexusapi/content_category_resource.rb +0 -2
  73. data/lib/appnexusapi/creative_resource.rb +0 -2
  74. data/lib/appnexusapi/creative_template_resource.rb +0 -2
  75. data/lib/appnexusapi/device_model_resource.rb +0 -2
  76. data/lib/appnexusapi/device_model_service.rb +0 -6
  77. data/lib/appnexusapi/domain_list_resource.rb +0 -2
  78. data/lib/appnexusapi/inventory_attribute_resource.rb +0 -2
  79. data/lib/appnexusapi/inventory_attribute_service.rb +0 -8
  80. data/lib/appnexusapi/inventory_source_resource.rb +0 -2
  81. data/lib/appnexusapi/language_resource.rb +0 -2
  82. data/lib/appnexusapi/language_service.rb +0 -8
  83. data/lib/appnexusapi/line_item_resource.rb +0 -2
  84. data/lib/appnexusapi/log_level_data_download_service.rb +0 -68
  85. data/lib/appnexusapi/log_level_data_resource.rb +0 -19
  86. data/lib/appnexusapi/log_level_data_service.rb +0 -26
  87. data/lib/appnexusapi/media_type_resource.rb +0 -2
  88. data/lib/appnexusapi/media_type_service.rb +0 -8
  89. data/lib/appnexusapi/member_resource.rb +0 -2
  90. data/lib/appnexusapi/object_limit_resource.rb +0 -2
  91. data/lib/appnexusapi/operating_system_extended_resource.rb +0 -2
  92. data/lib/appnexusapi/operating_system_resource.rb +0 -2
  93. data/lib/appnexusapi/operating_system_service.rb +0 -8
  94. data/lib/appnexusapi/payment_rule_resource.rb +0 -2
  95. data/lib/appnexusapi/placement_resource.rb +0 -2
  96. data/lib/appnexusapi/platform_member_resource.rb +0 -2
  97. data/lib/appnexusapi/platform_member_service.rb +0 -8
  98. data/lib/appnexusapi/profile_resource.rb +0 -2
  99. data/lib/appnexusapi/publisher_resource.rb +0 -2
  100. data/lib/appnexusapi/segment_resource.rb +0 -2
  101. data/lib/appnexusapi/site_resource.rb +0 -2
  102. data/lib/appnexusapi/technical_attribute_resource.rb +0 -2
  103. data/lib/appnexusapi/technical_attribute_service.rb +0 -8
  104. data/lib/appnexusapi/tiny_tag_resource.rb +0 -2
  105. data/lib/appnexusapi/user_resource.rb +0 -2
@@ -1,2 +0,0 @@
1
- class AppnexusApi::AdServerResource < AppnexusApi::Resource
2
- end
@@ -1,20 +0,0 @@
1
- class AppnexusApi::AdServerService < AppnexusApi::Service
2
-
3
- def initialize(connection)
4
- @read_only = true
5
- super(connection)
6
- end
7
-
8
- def name
9
- "adserver"
10
- end
11
-
12
- def resource_class
13
- ApnexusApi::AdServerResource
14
- end
15
-
16
- def uri_suffix
17
- "ad-server"
18
- end
19
-
20
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::AdvertiserResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::BidderInstanceResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::BidderProfileResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::BidderResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::BrandResource < AppnexusApi::Resource
2
- end
@@ -1,8 +0,0 @@
1
- class AppnexusApi::BrandService < AppnexusApi::Service
2
-
3
- def initialize(connection
4
- @read_only = true
5
- super(connection)
6
- end
7
-
8
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::BrowserResource < AppnexusApi::Resource
2
- end
@@ -1,8 +0,0 @@
1
- class AppnexusApi::BrowserService < AppnexusApi::Service
2
-
3
- def initialize(connection)
4
- @read_only = true
5
- super(connection)
6
- end
7
-
8
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::CampaignResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::CategoryResource < AppnexusApi::Resource
2
- end
@@ -1,12 +0,0 @@
1
- class AppnexusApi::CategoryService < AppnexusApi::Service
2
-
3
- def initialize(connection)
4
- @read_only = true
5
- super(connection)
6
- end
7
-
8
- def plural_name
9
- "categories"
10
- end
11
-
12
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::ContentCategoryResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::CreativeResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::CreativeTemplateResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::DeviceModelResource < AppnexusApi::Resource
2
- end
@@ -1,6 +0,0 @@
1
- class AppnexusApi::DeviceModelService < AppnexusApi::Service
2
- def initialize(connection)
3
- @read_only = true
4
- super(connection)
5
- end
6
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::DomainListResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::InventoryAttributeResource < AppnexusApi::Resource
2
- end
@@ -1,8 +0,0 @@
1
- class AppnexusApi::InventoryAttributeService < AppnexusApi::Service
2
-
3
- def initialize(connection)
4
- @read_only = true
5
- super(connection)
6
- end
7
-
8
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::InventorySourceResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::LanguageResource < AppnexusApi::Resource
2
- end
@@ -1,8 +0,0 @@
1
- class AppnexusApi::LanguageService < AppnexusApi::Service
2
-
3
- def initialize(connection)
4
- @read_only = true
5
- super(connection)
6
- end
7
-
8
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::LineItemResource < AppnexusApi::Resource
2
- end
@@ -1,68 +0,0 @@
1
- class AppnexusApi::LogLevelDataDownloadService < AppnexusApi::Service
2
- class BadChecksumException < Exception
3
- end
4
-
5
- def initialize(connection, options = {})
6
- @read_only = true
7
- @downloaded_files_path = options[:downloaded_files_path] || '.'
8
- super(connection)
9
- end
10
-
11
- def download_location(params = {})
12
- @connection.get(uri_suffix, params).headers['location']
13
- end
14
-
15
- # Parameter is a LogLevelDataResource
16
- # Downloads a gzipped file
17
- # Returns an array of paths to downloaded files
18
- def download_resource(data_resource)
19
- data_resource.download_params.map do |params|
20
- uri = URI.parse(download_location(params.reject { |k,v| k == :checksum }))
21
- filename = File.join(@downloaded_files_path, "#{params[:siphon_name]}_#{params[:hour]}_#{params[:split_part]}.gz")
22
- Pester.retry_with_exponential_backoff do
23
- download_file(uri, filename)
24
- calculated_checksum = Digest::MD5.hexdigest(File.read(filename))
25
- if calculated_checksum != params[:checksum]
26
- error_message = "Calculated checksum of #{calculated_checksum} doesn't match API provided checksum #{params[:checksum]}"
27
- puts error_message
28
- fail(BadChecksumException, error_message)
29
- end
30
- end
31
-
32
- filename
33
- end
34
- end
35
-
36
- def get
37
- fail(AppnexusApi::NotImplemented, 'This service is designed to work through download_location method.')
38
- end
39
-
40
- def uri_name
41
- 'siphon-download'
42
- end
43
-
44
- private
45
-
46
- def download_file(uri, filename)
47
- puts "Starting HTTP download for: #{uri.to_s}..."
48
- http_object = Net::HTTP.new(uri.host, uri.port)
49
- http_object.use_ssl = true if uri.scheme == 'https'
50
- begin
51
- http_object.start do |http|
52
- request = Net::HTTP::Get.new(uri.request_uri)
53
- http.read_timeout = 500
54
- http.request(request) do |response|
55
- open(filename, 'wb') do |io|
56
- response.read_body do |chunk|
57
- io.write(chunk)
58
- end
59
- end
60
- end
61
- end
62
- rescue StandardError => e
63
- puts "=> Exception: '#{e}'. Skipping download."
64
- return
65
- end
66
- puts "Stored download as #{filename}"
67
- end
68
- end
@@ -1,19 +0,0 @@
1
- class AppnexusApi::LogLevelDataResource < AppnexusApi::Resource
2
- # Extract an array of hashes of params to pass to the LogLevelDownloadService
3
- def download_params
4
- fail 'Missing necessaray information!' unless name && hour && timestamp && splits
5
-
6
- splits.map do |split_part|
7
- # In the case of regenerated files, there should be no checksum. These replaced hourly files should not be downloaded.
8
- next nil if split_part['checksum'].blank?
9
-
10
- {
11
- split_part: split_part['part'],
12
- siphon_name: name,
13
- timestamp: timestamp,
14
- hour: hour,
15
- checksum: split_part['checksum']
16
- }
17
- end.compact
18
- end
19
- end
@@ -1,26 +0,0 @@
1
- class AppnexusApi::LogLevelDataService < AppnexusApi::Service
2
- def initialize(connection, options = {})
3
- @read_only = true
4
- @siphon_name = options[:siphon_name]
5
-
6
- super(connection)
7
- end
8
-
9
- def since(time = nil)
10
- params = {}
11
- params[:siphon_name] = @siphon_name if @siphon_name
12
- params[:updated_since] = time.strftime('%Y_%m_%d_%H') if time
13
-
14
- # Anything with the same name and hour but with a newer timestamp is a republished replacement for an older file
15
- # When this happens appnexus is supposed to set the checksum for the old file to null but they do not always
16
- # actually do this.
17
- siphons = get(params)
18
- siphons.reject do |siphon|
19
- (siphons - [siphon]).any? { |s| s.name == siphon.name && s.hour == siphon.hour && s.timestamp > siphon.timestamp }
20
- end
21
- end
22
-
23
- def uri_name
24
- 'siphon'
25
- end
26
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::MediaTypeResource < AppnexusApi::Resource
2
- end
@@ -1,8 +0,0 @@
1
- class AppnexusApi::MediaTypeService < AppnexusApi::Service
2
-
3
- def initialize(connection)
4
- @read_only = true
5
- super(connection)
6
- end
7
-
8
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::MemberResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::ObjectLimitResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::OperatingSystemExtendedResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::OperatingSystemResource < AppnexusApi::Resource
2
- end
@@ -1,8 +0,0 @@
1
- class AppnexusApi::OperatingSystemService < AppnexusApi::Service
2
-
3
- def initialize(connection)
4
- @read_only = true
5
- super(connection)
6
- end
7
-
8
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::PaymentRuleResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::PlacementResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::PlatformMemberResource < AppnexusApi::Resource
2
- end
@@ -1,8 +0,0 @@
1
- class AppnexusApi::PlatformMemberService < AppnexusApi::Service
2
-
3
- def initialize(connection)
4
- @read_only = true
5
- super(connection)
6
- end
7
-
8
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::ProfileResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::PublisherResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::SegmentResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::SiteResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::TechnicalAttributeService < AppnexusApi::Resource
2
- end
@@ -1,8 +0,0 @@
1
- class AppnexusApi::TechnicalAttributeService < AppnexusApi::Service
2
-
3
- def initialize(connection)
4
- @read_only = true
5
- super(connection)
6
- end
7
-
8
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::TinyTagResource < AppnexusApi::Resource
2
- end
@@ -1,2 +0,0 @@
1
- class AppnexusApi::UserResource < AppnexusApi::Resource
2
- end