hasoffersv3 0.2.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +13 -0
  5. data/README.md +36 -3
  6. data/hasoffersv3.gemspec +4 -4
  7. data/lib/hasoffersv3/advertiser.rb +9 -11
  8. data/lib/hasoffersv3/advertiser_billing.rb +18 -20
  9. data/lib/hasoffersv3/advertiser_user.rb +2 -4
  10. data/lib/hasoffersv3/affiliate.rb +21 -23
  11. data/lib/hasoffersv3/affiliate_billing.rb +19 -21
  12. data/lib/hasoffersv3/affiliate_offer.rb +27 -27
  13. data/lib/hasoffersv3/application.rb +2 -4
  14. data/lib/hasoffersv3/base.rb +53 -38
  15. data/lib/hasoffersv3/client.rb +1 -1
  16. data/lib/hasoffersv3/configuration.rb +1 -0
  17. data/lib/hasoffersv3/conversion.rb +8 -15
  18. data/lib/hasoffersv3/employee.rb +17 -0
  19. data/lib/hasoffersv3/offer.rb +52 -54
  20. data/lib/hasoffersv3/offer_pixel.rb +22 -0
  21. data/lib/hasoffersv3/raw_log.rb +14 -16
  22. data/lib/hasoffersv3/report.rb +7 -21
  23. data/lib/hasoffersv3/version.rb +1 -1
  24. data/lib/hasoffersv3.rb +8 -3
  25. data/spec/lib/advertiser_billing_spec.rb +5 -4
  26. data/spec/lib/advertiser_spec.rb +1 -1
  27. data/spec/lib/advertiser_user_spec.rb +1 -1
  28. data/spec/lib/affiliate_billing_spec.rb +1 -1
  29. data/spec/lib/affiliate_offer_spec.rb +1 -1
  30. data/spec/lib/affiliate_spec.rb +1 -1
  31. data/spec/lib/conversion_spec.rb +3 -8
  32. data/spec/lib/employee_spec.rb +47 -0
  33. data/spec/lib/hasoffersv3_spec.rb +9 -1
  34. data/spec/lib/offer_pixel_spec.rb +76 -0
  35. data/spec/lib/offer_spec.rb +1 -1
  36. data/spec/lib/raw_log_spec.rb +1 -1
  37. data/spec/lib/report_spec.rb +5 -15
  38. metadata +8 -7
  39. data/.ruby-gemset +0 -1
  40. data/lib/hasoffersv3/adapter.rb +0 -30
  41. data/spec/lib/adapter_spec.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14bbd72a409f04c3d63cf07b9417afdde9c296a7
4
- data.tar.gz: 94b5449a542c94b181efa8f3b83fe34b45304f18
3
+ metadata.gz: 488904130364dca63aaebe483eb85f170bc768ec
4
+ data.tar.gz: d8e5195ff89cee5f418bf1a806a5b7018a0487ca
5
5
  SHA512:
6
- metadata.gz: aa0db833b68b053dd514b5a0f6fde0ed8a8152f7f5c9f7b4256133afca5d83275313e0cd5d95d2d848b9b973f440eb5750ff4b435cfb1749aba0a674da7555c3
7
- data.tar.gz: be9248e2502ead5ab04769039b52017f1cca049de8b9a8801ae29e8d03166b4bfcbd9593f74ae9b994f7b5e7dead15b76d80f31e12e73014b54ad9f41c86161c
6
+ metadata.gz: 3851200de016fdbe5e357e93847e333db04cfe8284849b60bc9dfd64d636eb52154b76ba80286431268b53e937680d25f33b47a2c21259847d26caf63ca856be
7
+ data.tar.gz: 35a1c685c0b32a8db00102bfbbb6bc8326e56724f4e2a5271e9ac381bf3734101b7fb305a19c0c90bf54e02720e80b80d371f5c14b041fc823b4acf209268696
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.2.2
data/.travis.yml CHANGED
@@ -3,6 +3,6 @@ script: bundle exec rspec spec
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - 2.1.1
7
6
  - 2.1.2
7
+ - 2.2.2
8
8
  - ruby-head
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # 0.4.0
2
+ - [#42] Support "Employee": findAll, find_all_by_ids and find_by_id
3
+ - [#41] Added config option `read_timeout` to changed default timeout to 60
4
+
5
+ # 0.3.0
6
+ - [#39] Removed depreacted methods. Updated structure to use separated client configs.
7
+
8
+ # 0.2.7
9
+ - [#37][#38] Support "OfferPixel": findAll, find_all_by_ids, find_by_id, get_allowed_types
10
+
11
+ # 0.2.6
12
+ - Use `https` by default
13
+
1
14
  # 0.2.5
2
15
  - Support "Application/findAllAffiliateTiers" method
3
16
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ### Overview
2
2
 
3
- [![Build status](https://api.travis-ci.org/applift/hasoffersv3.png?branch=master)](http://travis-ci.org/HitFox/hasoffersv3)
3
+ [![Build status](https://api.travis-ci.org/applift/hasoffersv3.png?branch=master)](http://travis-ci.org/applift/hasoffersv3)
4
4
 
5
5
  ### Synopsis
6
6
 
@@ -21,7 +21,20 @@ Supported ruby versions:
21
21
 
22
22
  ## Usage
23
23
 
24
- Basic usage:
24
+ First, check if the method you want to call is already defined in `hasoffersv3/lib/hasoffersv3/*`. If not, you will need to add the method yourself (either just use your fork or submit a PR with your changes).
25
+
26
+ Next, create an initializer in your project in `config/intializers` and configure your API credentials like so:
27
+
28
+ ```ruby
29
+ HasOffersV3.configure do |config|
30
+ config.api_key = ENV['YOUR_HAS_OFFERS_API_KEY']
31
+ config.network_id = ENV['YOUR_HAS_OFFERS_NETWORK_ID']
32
+ config.read_timeout = 10
33
+ end
34
+ ```
35
+
36
+ You can now use the defined methods, following this pattern:
37
+
25
38
 
26
39
  ```ruby
27
40
  HasOffersV3::ControllerName.snake_case_method_name
@@ -34,7 +47,27 @@ Naming is the same as in HasOffers documentation, also if it requires attributes
34
47
  Examples:
35
48
 
36
49
  ```ruby
37
- HasOffersV3::Affiliate.update_payment_method_wire affiliate_id: '877', data: []
50
+ HasOffersV3::Affiliate.update_payment_method_wire({ affiliate_id: '877', data: {} })
51
+ ```
52
+
53
+ or when working with forms:
54
+
55
+ ```ruby
56
+ HasOffersV3::Advertiser.signup({
57
+ account: {
58
+ company: params[:company_name],
59
+ country: params[:company_country],
60
+ address1: 'Change me 123',
61
+ zipcode: '123123'
62
+ },
63
+ user: {
64
+ first_name: params[:user_name],
65
+ email: params[:user_email],
66
+ password: params[:user_password],
67
+ password_confirmation: params[:user_password_confirmation]
68
+ },
69
+ return_object: 1
70
+ })
38
71
  ```
39
72
 
40
73
  ## Testing
data/hasoffersv3.gemspec CHANGED
@@ -4,11 +4,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'hasoffersv3/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "hasoffersv3"
7
+ s.name = 'hasoffersv3'
8
8
  s.version = HasOffersV3::VERSION
9
9
  s.platform = Gem::Platform::RUBY
10
- s.authors = ["Maximilian Seifert", "Timo Rößner"]
11
- s.email = ["ms@hitfox.com", "tr@hitfox.com"]
10
+ s.authors = ['Maximilian Seifert', 'Timo Rößner']
11
+ s.email = ['ms@hitfox.com', 'tr@hitfox.com']
12
12
  s.summary = %q{REST Client for the HasOffers API, version 3.}
13
13
  s.description = %q{REST Client for the HasOffers API, version 3.}
14
14
  s.license = "MIT"
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.files = `git ls-files`.split($/)
17
17
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
18
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
- s.require_paths = ["lib"]
19
+ s.require_paths = ['lib']
20
20
 
21
21
  s.add_dependency 'activesupport' # for to_param method
22
22
  s.add_development_dependency 'webmock'
@@ -1,18 +1,16 @@
1
1
  class HasOffersV3
2
2
  class Advertiser < Base
3
- class << self
4
- def find_all_ids
5
- post_request 'findAllIds', {}
6
- end
3
+ def find_all_ids
4
+ post_request 'findAllIds', {}
5
+ end
7
6
 
8
- def find_all(params = {})
9
- post_request 'findAll', params
10
- end
7
+ def find_all(params = {})
8
+ post_request 'findAll', params
9
+ end
11
10
 
12
- def find_by_id(params = {})
13
- requires! params, [:id]
14
- post_request 'findById', params
15
- end
11
+ def find_by_id(params = {})
12
+ requires! params, [:id]
13
+ post_request 'findById', params
16
14
  end
17
15
  end
18
16
  end
@@ -1,29 +1,27 @@
1
1
  class HasOffersV3
2
2
  class AdvertiserBilling < Base
3
- class << self
4
- def find_all_invoices(params = {})
5
- post_request 'findAllInvoices', params
6
- end
3
+ def find_all_invoices(params = {})
4
+ post_request 'findAllInvoices', params
5
+ end
7
6
 
8
- def create_invoice(params = {})
9
- requires! params, [:data]
10
- post_request 'createInvoice', params
11
- end
7
+ def create_invoice(params = {})
8
+ requires! params, [:data]
9
+ post_request 'createInvoice', params
10
+ end
12
11
 
13
- def find_invoice_by_id(params = {})
14
- requires! params, [:id]
15
- post_request 'findInvoiceById', params
16
- end
12
+ def find_invoice_by_id(params = {})
13
+ requires! params, [:id]
14
+ post_request 'findInvoiceById', params
15
+ end
17
16
 
18
- def add_invoice_item(params = {})
19
- requires! params, [:invoice_id, :data]
20
- post_request 'addInvoiceItem', params
21
- end
17
+ def add_invoice_item(params = {})
18
+ requires! params, [:invoice_id, :data]
19
+ post_request 'addInvoiceItem', params
20
+ end
22
21
 
23
- def remove_invoice_item(params = {})
24
- requires! params, [:id]
25
- post_request 'removeInvoiceItem', params
26
- end
22
+ def remove_invoice_item(params = {})
23
+ requires! params, [:id]
24
+ post_request 'removeInvoiceItem', params
27
25
  end
28
26
  end
29
27
  end
@@ -1,9 +1,7 @@
1
1
  class HasOffersV3
2
2
  class AdvertiserUser < Base
3
- class << self
4
- def find_all(params = {})
5
- post_request 'findAll', params
6
- end
3
+ def find_all(params = {})
4
+ post_request 'findAll', params
7
5
  end
8
6
  end
9
7
  end
@@ -1,33 +1,31 @@
1
1
  class HasOffersV3
2
2
  class Affiliate < Base
3
- class << self
4
- def find_all(params = {})
5
- post_request 'findAll', params
6
- end
3
+ def find_all(params = {})
4
+ post_request 'findAll', params
5
+ end
7
6
 
8
- def find_by_id(params = {})
9
- requires! params, [:id]
10
- get_request 'findById', params
11
- end
7
+ def find_by_id(params = {})
8
+ requires! params, [:id]
9
+ get_request 'findById', params
10
+ end
12
11
 
13
- def update_payment_method_wire(params = {})
14
- post_request 'updatePaymentMethodWire', params
15
- end
12
+ def update_payment_method_wire(params = {})
13
+ post_request 'updatePaymentMethodWire', params
14
+ end
16
15
 
17
- def update_payment_method_paypal(params = {})
18
- post_request 'updatePaymentMethodPaypal', params
19
- end
16
+ def update_payment_method_paypal(params = {})
17
+ post_request 'updatePaymentMethodPaypal', params
18
+ end
20
19
 
21
- def create (params = {})
22
- requires! params, [:data]
23
- requires! params[:data], [:zipcode, :company]
24
- post_request 'create', params
25
- end
20
+ def create (params = {})
21
+ requires! params, [:data]
22
+ requires! params[:data], [:zipcode, :company]
23
+ post_request 'create', params
24
+ end
26
25
 
27
- def get_tier(params = {})
28
- requires! params, [:id]
29
- post_request 'getAffiliateTier', params
30
- end
26
+ def get_tier(params = {})
27
+ requires! params, [:id]
28
+ post_request 'getAffiliateTier', params
31
29
  end
32
30
  end
33
31
  end
@@ -1,30 +1,28 @@
1
1
  class HasOffersV3
2
2
  class AffiliateBilling < Base
3
- class << self
4
- def find_last_invoice(params = {})
5
- requires! params, [:affiliate_id]
6
- post_request 'findLastInvoice', params
7
- end
3
+ def find_last_invoice(params = {})
4
+ requires! params, [:affiliate_id]
5
+ post_request 'findLastInvoice', params
6
+ end
8
7
 
9
- def create_invoice(params = {})
10
- requires! params, [:data]
11
- post_request 'createInvoice', params
12
- end
8
+ def create_invoice(params = {})
9
+ requires! params, [:data]
10
+ post_request 'createInvoice', params
11
+ end
13
12
 
14
- def find_invoice_by_id(params = {})
15
- requires! params, [:id]
16
- post_request 'findInvoiceById', params
17
- end
13
+ def find_invoice_by_id(params = {})
14
+ requires! params, [:id]
15
+ post_request 'findInvoiceById', params
16
+ end
18
17
 
19
- def add_invoice_item(params = {})
20
- requires! params, [:invoice_id, :data]
21
- post_request 'addInvoiceItem', params
22
- end
18
+ def add_invoice_item(params = {})
19
+ requires! params, [:invoice_id, :data]
20
+ post_request 'addInvoiceItem', params
21
+ end
23
22
 
24
- def remove_invoice_item(params = {})
25
- requires! params, [:id]
26
- post_request 'removeInvoiceItem', params
27
- end
23
+ def remove_invoice_item(params = {})
24
+ requires! params, [:id]
25
+ post_request 'removeInvoiceItem', params
28
26
  end
29
27
  end
30
28
  end
@@ -1,39 +1,39 @@
1
1
  class HasOffersV3
2
2
  class AffiliateOffer < Base
3
- class << self
4
-
5
- def target
6
- 'Affiliate_Offer'
7
- end
3
+ def self.target
4
+ 'Affiliate_Offer'
5
+ end
8
6
 
9
- def find_all(params = {})
10
- post_request 'findAll', params
11
- end
7
+ def target
8
+ 'Affiliate_Offer'
9
+ end
12
10
 
13
- def find_by_id(params = {})
14
- requires! params, [:id]
15
- post_request 'findById', params
16
- end
11
+ def find_all(params = {})
12
+ post_request 'findAll', params
13
+ end
17
14
 
18
- def get_categories(params = {})
19
- requires! params, [:ids]
20
- post_request 'getCategories', params
21
- end
15
+ def find_by_id(params = {})
16
+ requires! params, [:id]
17
+ post_request 'findById', params
18
+ end
22
19
 
23
- def get_target_countries(params = {})
24
- requires! params, [:ids]
25
- post_request 'getTargetCountries', params
26
- end
20
+ def get_categories(params = {})
21
+ requires! params, [:ids]
22
+ post_request 'getCategories', params
23
+ end
27
24
 
28
- def generate_tracking_link(params = {})
29
- requires! params, [:offer_id]
30
- post_request 'generateTrackingLink', params
31
- end
25
+ def get_target_countries(params = {})
26
+ requires! params, [:ids]
27
+ post_request 'getTargetCountries', params
28
+ end
32
29
 
33
- def find_my_offers(params = {})
34
- post_request 'findMyOffers', params
35
- end
30
+ def generate_tracking_link(params = {})
31
+ requires! params, [:offer_id]
32
+ post_request 'generateTrackingLink', params
33
+ end
36
34
 
35
+ def find_my_offers(params = {})
36
+ post_request 'findMyOffers', params
37
37
  end
38
38
  end
39
39
  end
@@ -1,9 +1,7 @@
1
1
  class HasOffersV3
2
2
  class Application < Base
3
- class << self
4
- def get_payout_tiers(params = {})
5
- get_request 'findAllAffiliateTiers', params
6
- end
3
+ def get_payout_tiers(params = {})
4
+ get_request 'findAllAffiliateTiers', params
7
5
  end
8
6
  end
9
7
  end
@@ -3,43 +3,11 @@ require 'active_support/core_ext/object/to_query'
3
3
 
4
4
  class HasOffersV3
5
5
  class Base
6
- class << self
7
- def get_request(method, params = {}, &block)
8
- if block.nil?
9
- make_request(:get, method, params)
10
- else
11
- page = 1
12
- begin
13
- response = make_request(:get, method, params.merge(page: page))
14
- block.call response
15
- page += 1
16
- end until page > (response.page_info['page_count'] || 1)
17
- end
18
- end
19
-
20
- def post_request(method, params = {}, &block)
21
- if block.nil?
22
- make_request(:post, method, params)
23
- else
24
- page = 1
25
- begin
26
- response = make_request(:post, method, params.merge(page: page))
27
- block.call response
28
- page += 1
29
- end until page > (response.page_info['page_count'] || 1)
30
- end
31
- end
32
-
33
- def requires!(hash, required_params)
34
- missing_params = []
35
- required_params.each do |param|
36
- missing_params.push param unless hash.has_key?(param)
37
- end
38
- unless missing_params.empty?
39
- raise ArgumentError.new("Missing required parameter(s): #{missing_params.join(', ')}")
40
- end
41
- end
6
+ def initialize(client = HasOffersV3.client)
7
+ @client = client
8
+ end
42
9
 
10
+ class << self
43
11
  def target
44
12
  name.split('::').last
45
13
  end
@@ -48,16 +16,63 @@ class HasOffersV3
48
16
  HasOffersV3.client
49
17
  end
50
18
 
19
+ def method_missing(meth, *args, &block)
20
+ new(client).send(meth, *args, &block)
21
+ end
22
+
51
23
  private
52
24
 
53
25
  def deprecation(from, to)
54
26
  warn "\033[31m[DEPRECATION] `#{ name }.#{ from }` is deprecated. Please use `#{ name }.#{ to }` instead.\033[0m"
55
27
  end
28
+ end
29
+
30
+ def get_request(method, params = {}, &block)
31
+ if block.nil?
32
+ make_request(:get, method, params)
33
+ else
34
+ page = 1
35
+ begin
36
+ response = make_request(:get, method, params.merge(page: page))
37
+ block.call response
38
+ page += 1
39
+ end until page > (response.page_info['page_count'] || 1)
40
+ end
41
+ end
56
42
 
57
- def make_request(http_method, method, params)
58
- client.request(http_method, target, method, params)
43
+ def post_request(method, params = {}, &block)
44
+ if block.nil?
45
+ make_request(:post, method, params)
46
+ else
47
+ page = 1
48
+ begin
49
+ response = make_request(:post, method, params.merge(page: page))
50
+ block.call response
51
+ page += 1
52
+ end until page > (response.page_info['page_count'] || 1)
59
53
  end
54
+ end
55
+
56
+ def requires!(hash, required_params)
57
+ missing_params = []
58
+ required_params.each do |param|
59
+ missing_params.push param unless hash.has_key?(param)
60
+ end
61
+ unless missing_params.empty?
62
+ raise ArgumentError.new("Missing required parameter(s): #{missing_params.join(', ')}")
63
+ end
64
+ end
65
+
66
+ def target
67
+ self.class.target
68
+ end
69
+
70
+ def client
71
+ @client
72
+ end
60
73
 
74
+ def make_request(http_method, method, params)
75
+ @client.request(http_method, target, method, params)
61
76
  end
62
77
  end
63
78
  end
@@ -52,7 +52,7 @@ class HasOffersV3
52
52
  def new_http(uri)
53
53
  http = Net::HTTP.new(uri.host, uri.port)
54
54
  http.use_ssl = true if uri.scheme == 'https'
55
- http.read_timeout = 600
55
+ http.read_timeout = configuration.read_timeout
56
56
  http
57
57
  end
58
58
 
@@ -15,6 +15,7 @@ class HasOffersV3
15
15
  DEFAULTS = {
16
16
  host: 'api.hasoffers.com',
17
17
  protocol: 'https',
18
+ read_timeout: 60,
18
19
  base_path: '/v3',
19
20
  network_id: '',
20
21
  api_key: '',
@@ -1,22 +1,15 @@
1
1
  class HasOffersV3
2
2
  class Conversion < Base
3
- class << self
4
- def findAll(params = {})
5
- deprecation 'findAll', 'find_all'
6
- find_all params
7
- end
8
-
9
- def find_all(params = {})
10
- get_request 'findAll', params
11
- end
3
+ def find_all(params = {})
4
+ get_request 'findAll', params
5
+ end
12
6
 
13
- def find_added_conversions(params = {})
14
- get_request 'findAddedConversions', params
15
- end
7
+ def find_added_conversions(params = {})
8
+ get_request 'findAddedConversions', params
9
+ end
16
10
 
17
- def find_updated_conversions(params = {})
18
- get_request 'findUpdatedConversions', params
19
- end
11
+ def find_updated_conversions(params = {})
12
+ get_request 'findUpdatedConversions', params
20
13
  end
21
14
  end
22
15
  end
@@ -0,0 +1,17 @@
1
+ class HasOffersV3
2
+ class Employee < Base
3
+ def find_all(params = {})
4
+ post_request 'findAll', params
5
+ end
6
+
7
+ def find_all_by_ids(params = {})
8
+ requires! params, [:ids]
9
+ post_request 'findAllByIds', params
10
+ end
11
+
12
+ def find_by_id(params = {})
13
+ requires! params, [:id]
14
+ post_request 'findById', params
15
+ end
16
+ end
17
+ end