hasoffersv3 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/hasoffersv3.gemspec +27 -0
- data/lib/hasoffersv3/advertiser.rb +18 -0
- data/lib/hasoffersv3/advertiser_user.rb +9 -0
- data/lib/hasoffersv3/affiliate.rb +22 -0
- data/lib/hasoffersv3/base.rb +92 -0
- data/lib/hasoffersv3/configuration.rb +9 -0
- data/lib/hasoffersv3/conversion.rb +14 -0
- data/lib/hasoffersv3/offer.rb +29 -0
- data/lib/hasoffersv3/raw_log.rb +24 -0
- data/lib/hasoffersv3/report.rb +27 -0
- data/lib/hasoffersv3/response.rb +78 -0
- data/lib/hasoffersv3/testing.rb +53 -0
- data/lib/hasoffersv3/version.rb +3 -0
- data/lib/hasoffersv3.rb +20 -0
- data/spec/lib/advertiser_spec.rb +40 -0
- data/spec/lib/advertiser_user_spec.rb +16 -0
- data/spec/lib/affiliate_spec.rb +48 -0
- data/spec/lib/base_spec.rb +9 -0
- data/spec/lib/conversion_spec.rb +37 -0
- data/spec/lib/offer_spec.rb +76 -0
- data/spec/lib/report_spec.rb +71 -0
- data/spec/spec_helper.rb +52 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b1f94908bc73b00a0152fbf3ad054a776f268518
|
4
|
+
data.tar.gz: 06dfd698ca5f91d43105207f0638558fc3c2993b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93bcc4325bda19af9b1c4e3f19443dfdda45fd2fc7999a566b1b0e4ebfc48b4a1036fff65181472f6041ee84824038934ea0cb88b95f8befdce8af3cd28e81a0
|
7
|
+
data.tar.gz: 5436dd964dd12c9f8226710a41787fa6cf27ab18a07157043df963191e655f3ad24c0ae56a4ce722f85373efd4589c3e2dd52498c077b3919f61a503321a5f97
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
hasoffersv3
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p353
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Timo Rößner
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Ruby wrapper for HasOffers APIv3
|
2
|
+
|
3
|
+
Gem provides wrapper around HasOffers API in version 3, [HasOffers APIv3 Documentation](http://developers.hasoffers.com/#/brand).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install hasoffersv3
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Basic usage:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
HasOffersV3::ControllerName.snake_case_method_name
|
15
|
+
```
|
16
|
+
|
17
|
+
If HasOffers method does not take any parameters, then API also doesn't take them, otherwise it should be always a hash.
|
18
|
+
|
19
|
+
Naming is the same as in HasOffers documentation, also if it requires attributes then API will raise an exception if it's missing.
|
20
|
+
|
21
|
+
Examples:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
HasOffersV3::Affiliate.update_payment_method_wire affiliate_id: '877', data: []
|
25
|
+
```
|
26
|
+
|
27
|
+
## Testing
|
28
|
+
|
29
|
+
If `RAILS_ENV` or `RACK_ENV` is set to `test`, or there's a `TEST`
|
30
|
+
environment variable, it will require the HasOffersV3::Testing module
|
31
|
+
and enable testing mode. In testing mode all requests will return
|
32
|
+
stubbed successful response with empty data set.
|
33
|
+
|
34
|
+
When you need to disable testing mode:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
HasOffersV3::Testing.disable!
|
38
|
+
```
|
39
|
+
|
40
|
+
When you want to provide custom stub:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
HasOffersV3::Testing.stub_request status_code, body
|
44
|
+
```
|
data/Rakefile
ADDED
data/hasoffersv3.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hasoffersv3/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "hasoffersv3"
|
8
|
+
s.version = HasOffersV3::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Maximilian Seifert", "Timo Rößner"]
|
11
|
+
s.email = ["ms@hitfox.com", "tr@hitfox.com"]
|
12
|
+
s.summary = %q{REST Client for the HasOffers API, version 3.}
|
13
|
+
s.description = %q{REST Client for the HasOffers API, version 3.}
|
14
|
+
s.license = "MIT"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split($/)
|
17
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency 'oj' # for faster JSON parsing
|
22
|
+
s.add_dependency 'activesupport' # for to_param method
|
23
|
+
s.add_development_dependency 'webmock'
|
24
|
+
s.add_development_dependency 'rspec'
|
25
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
s.add_development_dependency "rake"
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module HasOffersV3
|
2
|
+
class Advertiser < Base
|
3
|
+
class << self
|
4
|
+
def find_all_ids
|
5
|
+
post_request 'findAllIds', {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def find_all(params = {})
|
9
|
+
post_request 'findAll', 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
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module HasOffersV3
|
2
|
+
class Affiliate < Base
|
3
|
+
class << self
|
4
|
+
def find_all(params = {})
|
5
|
+
post_request 'findAll', params
|
6
|
+
end
|
7
|
+
|
8
|
+
def find_by_id(params = {})
|
9
|
+
requires! params, [:id]
|
10
|
+
get_request 'findById', params
|
11
|
+
end
|
12
|
+
|
13
|
+
def update_payment_method_wire(params = {})
|
14
|
+
post_request 'updatePaymentMethodWire', params
|
15
|
+
end
|
16
|
+
|
17
|
+
def update_payment_method_paypal(params = {})
|
18
|
+
post_request 'updatePaymentMethodPaypal', params
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'net/http' if RUBY_VERSION < '2'
|
2
|
+
require 'active_support/core_ext/object/to_query'
|
3
|
+
|
4
|
+
module HasOffersV3
|
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
|
42
|
+
|
43
|
+
def target
|
44
|
+
name.split('::').last
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def deprecation(from, to)
|
50
|
+
warn "\033[31m[DEPRECATION] `#{ name }.#{ from }` is deprecated. Please use `#{ name }.#{ to }` instead.\033[0m"
|
51
|
+
end
|
52
|
+
|
53
|
+
def new_http(uri)
|
54
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
55
|
+
http.read_timeout = 600
|
56
|
+
http
|
57
|
+
end
|
58
|
+
|
59
|
+
def query_string(data_hash)
|
60
|
+
# Rails to_params adds an extra open close brackets to multi-dimensional array parameters which
|
61
|
+
# hasoffers doesn't like, so the gsub here takes care of that.
|
62
|
+
data_hash.to_param.gsub(/\[\]\[/,'[')
|
63
|
+
end
|
64
|
+
|
65
|
+
def make_request(http_method, method, params)
|
66
|
+
data = build_request_params(method, params)
|
67
|
+
if http_method == :post
|
68
|
+
uri = URI.parse("#{HasOffersV3.configuration.base_uri}/#{target}.json")
|
69
|
+
http = new_http(uri)
|
70
|
+
raw_request = Net::HTTP::Post.new(uri.request_uri)
|
71
|
+
raw_request.body = query_string data
|
72
|
+
else # assume get
|
73
|
+
uri = URI.parse("#{HasOffersV3.configuration.base_uri}/#{target}.json?#{query_string(data)}")
|
74
|
+
http = new_http(uri)
|
75
|
+
raw_request = Net::HTTP::Get.new(uri.request_uri)
|
76
|
+
end
|
77
|
+
http_response = execute_request(http, raw_request)
|
78
|
+
|
79
|
+
Response.new(http_response)
|
80
|
+
end
|
81
|
+
|
82
|
+
def execute_request(net_http, raw_request)
|
83
|
+
net_http.request raw_request
|
84
|
+
end
|
85
|
+
|
86
|
+
def build_request_params(method, params)
|
87
|
+
params['Method'] = method
|
88
|
+
params.merge NetworkId: HasOffersV3.configuration.network_id, NetworkToken: HasOffersV3.configuration.api_key
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module HasOffersV3
|
2
|
+
class Offer < Base
|
3
|
+
class << self
|
4
|
+
def find_all(params = {})
|
5
|
+
post_request 'findAll', params
|
6
|
+
end
|
7
|
+
|
8
|
+
def find_all_by_ids(params = {})
|
9
|
+
requires! params, [:ids]
|
10
|
+
post_request 'findAllByIds', params
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_all_ids_by_advertiser_id(params = {})
|
14
|
+
requires! params, [:advertiser_id]
|
15
|
+
post_request 'findAllIdsByAdvertiserId', params
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_by_id(params = {})
|
19
|
+
requires! params, [:id]
|
20
|
+
post_request 'findById', params
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_groups(params = {})
|
24
|
+
requires! params, [:id]
|
25
|
+
post_request 'getGroups', params
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module HasOffersV3
|
2
|
+
class RawLog < Base
|
3
|
+
class << self
|
4
|
+
def get_download_link(params = {})
|
5
|
+
requires! params, [:log_type, :log_filename]
|
6
|
+
get_request 'getDownloadLink', params
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_log_expirations(params = {})
|
10
|
+
get_request 'getLogExpirations', params
|
11
|
+
end
|
12
|
+
|
13
|
+
def list_date_dirs(params = {})
|
14
|
+
requires! params, [:log_type]
|
15
|
+
get_request 'listDateDirs', params
|
16
|
+
end
|
17
|
+
|
18
|
+
def list_logs(params = {})
|
19
|
+
requires! params, [:log_type, :date_dir]
|
20
|
+
get_request 'listLogs', params
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module HasOffersV3
|
2
|
+
class Report < Base
|
3
|
+
Target = 'Report'
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def getConversions(params = {}, &block)
|
7
|
+
deprecation 'getConversions', 'get_conversions'
|
8
|
+
get_conversions params, &block
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_conversions(params = {}, &block)
|
12
|
+
# TODO: This *should* be a GET request, however, if we use that here we get: "The requested URL's length exceeds the capacity limit for this server."
|
13
|
+
# because the number of affiliate_ids we pass in is too high.
|
14
|
+
post_request 'getConversions', params, &block
|
15
|
+
end
|
16
|
+
|
17
|
+
def getModSummaryLogs(params = {}, &block)
|
18
|
+
deprecation 'getModSummaryLogs', 'get_mod_summary_logs'
|
19
|
+
get_mod_summary_logs params, &block
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_mod_summary_logs(params = {}, &block)
|
23
|
+
get_request 'getModSummaryLogs', params, &block
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'oj'
|
2
|
+
|
3
|
+
module HasOffersV3
|
4
|
+
class Response
|
5
|
+
attr_reader :body, :http_status_code, :http_message, :http_headers
|
6
|
+
|
7
|
+
def initialize(response)
|
8
|
+
@body = Oj.load(response.body.to_s)
|
9
|
+
@http_status_code = response.code
|
10
|
+
@http_message = response.message
|
11
|
+
@http_headers = response.to_hash
|
12
|
+
end
|
13
|
+
|
14
|
+
def success?
|
15
|
+
@http_status_code.to_s == '200' and status == 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def status
|
19
|
+
@body['response']['status']
|
20
|
+
end
|
21
|
+
|
22
|
+
def raw_data
|
23
|
+
@body
|
24
|
+
end
|
25
|
+
|
26
|
+
# allows specific api calls to post-process the data for ease of use
|
27
|
+
def set_data(data)
|
28
|
+
@processed_data = data
|
29
|
+
end
|
30
|
+
|
31
|
+
def data
|
32
|
+
@processed_data || (paginated_response? ? @body['response']['data']['data'] : @body['response']['data'])
|
33
|
+
end
|
34
|
+
|
35
|
+
def page_info
|
36
|
+
if paginated_response?
|
37
|
+
{
|
38
|
+
'page_count' => @body['response']['data']['pageCount'],
|
39
|
+
'current' => @body['response']['data']['current'],
|
40
|
+
'count' => @body['response']['data']['count'],
|
41
|
+
'page' => @body['response']['data']['page']
|
42
|
+
}
|
43
|
+
else
|
44
|
+
{}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def validation_error?
|
49
|
+
status == -1 and data['error_code'] == 1
|
50
|
+
end
|
51
|
+
|
52
|
+
def error_messages
|
53
|
+
if data.is_a? Hash and data["errors"] and data["errors"]["error"]
|
54
|
+
get_error_values data["errors"]["error"]
|
55
|
+
elsif @body["response"]["errors"]
|
56
|
+
get_error_values @body["response"]["errors"]
|
57
|
+
else
|
58
|
+
[]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
def paginated_response?
|
65
|
+
@body['response']['data'] and @body['response']['data'].is_a?(Hash) and @body['response']['data'].has_key?('pageCount')
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def get_error_values(obj)
|
71
|
+
if obj.is_a? Hash
|
72
|
+
obj.values
|
73
|
+
elsif obj.is_a? Array
|
74
|
+
obj.map { |error| error["err_msg"] || error["publicMessage"] }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module HasOffersV3
|
2
|
+
class Testing
|
3
|
+
class << self
|
4
|
+
attr_accessor :__test_mode, :__prepared_request
|
5
|
+
|
6
|
+
def enable!
|
7
|
+
self.__test_mode = :enabled
|
8
|
+
end
|
9
|
+
|
10
|
+
def disable!
|
11
|
+
self.__test_mode = :disabled
|
12
|
+
end
|
13
|
+
|
14
|
+
def enabled?
|
15
|
+
self.__test_mode == :enabled
|
16
|
+
end
|
17
|
+
|
18
|
+
def disabled?
|
19
|
+
self.__test_mode == :disabled
|
20
|
+
end
|
21
|
+
|
22
|
+
def stub_request(status = 200, body = '{"response":{"status":1,"data":[]}}', message = 'mock')
|
23
|
+
self.__prepared_request = begin
|
24
|
+
response = Net::HTTPResponse.new '1.1', status, message
|
25
|
+
response.stub(:body) { body }
|
26
|
+
response
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def execute_stubbed_request
|
31
|
+
current_request = self.__prepared_request || self.stub_request
|
32
|
+
self.__prepared_request = nil
|
33
|
+
current_request
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Base
|
39
|
+
class << self
|
40
|
+
private
|
41
|
+
|
42
|
+
alias_method :original_execute_request, :execute_request
|
43
|
+
|
44
|
+
def execute_request(net_http, raw_request)
|
45
|
+
if HasOffersV3::Testing.enabled?
|
46
|
+
HasOffersV3::Testing.execute_stubbed_request
|
47
|
+
else
|
48
|
+
original_execute_request net_http, raw_request
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/hasoffersv3.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
%w!base affiliate response conversion raw_log report configuration advertiser advertiser_user offer!.each do |file|
|
2
|
+
require "hasoffersv3/#{file}"
|
3
|
+
end
|
4
|
+
|
5
|
+
module HasOffersV3
|
6
|
+
class << self
|
7
|
+
def configuration
|
8
|
+
@configuration ||= Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def configure &block
|
12
|
+
block.call configuration
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if ENV['RAILS_ENV'] == 'test' || ENV['RACK_ENV'] == 'test' || ENV['TEST']
|
18
|
+
require 'hasoffersv3/testing'
|
19
|
+
HasOffersV3::Testing.enable!
|
20
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HasOffersV3::Advertiser do
|
4
|
+
subject { HasOffersV3::Advertiser }
|
5
|
+
|
6
|
+
let(:url) { api_url 'Advertiser' }
|
7
|
+
|
8
|
+
describe '.find_all' do
|
9
|
+
it 'should make a proper request call' do
|
10
|
+
stub_call
|
11
|
+
response = subject.find_all
|
12
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'findAll'})).should have_been_made
|
13
|
+
validate_call response
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.find_all_ids' do
|
18
|
+
it 'should make a proper request call' do
|
19
|
+
stub_call
|
20
|
+
response = subject.find_all_ids
|
21
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'findAllIds'})).should have_been_made
|
22
|
+
validate_call response
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.find_by_id' do
|
27
|
+
it 'should make a proper request call' do
|
28
|
+
stub_call
|
29
|
+
response = subject.find_by_id id: 1
|
30
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'findById', 'id' => '1'})).should have_been_made
|
31
|
+
validate_call response
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when there is no id' do
|
35
|
+
it 'should raise exception' do
|
36
|
+
expect { subject.find_by_id failed_id: 1 }.to raise_error ArgumentError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HasOffersV3::AdvertiserUser do
|
4
|
+
subject { HasOffersV3::AdvertiserUser }
|
5
|
+
|
6
|
+
let(:url) { api_url 'AdvertiserUser' }
|
7
|
+
|
8
|
+
describe '.find_all' do
|
9
|
+
it 'should make a proper request call' do
|
10
|
+
stub_call
|
11
|
+
response = subject.find_all
|
12
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'findAll'})).should have_been_made
|
13
|
+
validate_call response
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HasOffersV3::Affiliate do
|
4
|
+
subject { HasOffersV3::Affiliate }
|
5
|
+
|
6
|
+
let(:url) { api_url 'Affiliate' }
|
7
|
+
|
8
|
+
before(:each) { stub_call unless example.metadata[:no_stub] }
|
9
|
+
|
10
|
+
describe '.find_all' do
|
11
|
+
it 'should make a proper request call' do
|
12
|
+
response = subject.find_all
|
13
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'findAll'})).should have_been_made
|
14
|
+
validate_call response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.find_by_id', :no_stub do
|
19
|
+
it 'should make a proper request call' do
|
20
|
+
stub_call :get, nil, Regexp.new(url)
|
21
|
+
response = subject.find_by_id id: 1
|
22
|
+
a_request(:get, url).with(query: hash_including({'Method' => 'findById', 'id' => '1'})).should have_been_made
|
23
|
+
validate_call response
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when there is no id' do
|
27
|
+
it 'should raise exception' do
|
28
|
+
expect { subject.find_by_id failed_id: 1 }.to raise_error ArgumentError
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.update_payment_method_wire' do
|
34
|
+
it 'should make a proper request call' do
|
35
|
+
response = subject.update_payment_method_wire
|
36
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'updatePaymentMethodWire'})).should have_been_made
|
37
|
+
validate_call response
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '.update_payment_method_paypal' do
|
42
|
+
it 'should make a proper request call' do
|
43
|
+
response = subject.update_payment_method_paypal
|
44
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'updatePaymentMethodPaypal'})).should have_been_made
|
45
|
+
validate_call response
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HasOffersV3::Conversion do
|
4
|
+
subject { HasOffersV3::Conversion }
|
5
|
+
|
6
|
+
let(:url) { Regexp.new api_url('Conversion') }
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
stub_call :get
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.find_all' do
|
13
|
+
it 'should make a proper request call' do
|
14
|
+
response = subject.find_all
|
15
|
+
a_request(:get, url).with(query: hash_including({'Method' => 'findAll'})).should have_been_made
|
16
|
+
validate_call response
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.findAll' do
|
21
|
+
it 'should make a proper request call' do
|
22
|
+
response = subject.findAll
|
23
|
+
a_request(:get, url).with(query: hash_including({'Method' => 'findAll'})).should have_been_made
|
24
|
+
validate_call response
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should show a deprecation warning' do
|
28
|
+
expect(subject).to receive(:deprecation).with('findAll', 'find_all')
|
29
|
+
subject.findAll
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should call find_all method' do
|
33
|
+
expect(subject).to receive(:find_all).with({test: 1})
|
34
|
+
subject.findAll test: 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HasOffersV3::Offer do
|
4
|
+
subject { HasOffersV3::Offer }
|
5
|
+
|
6
|
+
let(:url) { api_url 'Offer' }
|
7
|
+
|
8
|
+
describe '.find_all' do
|
9
|
+
it 'should make a proper request call' do
|
10
|
+
stub_call
|
11
|
+
response = HasOffersV3::Offer.find_all
|
12
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'findAll'})).should have_been_made
|
13
|
+
validate_call response
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.find_all_by_ids' do
|
18
|
+
it 'should make a proper request call' do
|
19
|
+
stub_call
|
20
|
+
response = HasOffersV3::Offer.find_all_by_ids ids: [1]
|
21
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'findAllByIds'})).should have_been_made
|
22
|
+
validate_call response
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when there is no id' do
|
26
|
+
it 'should raise exception' do
|
27
|
+
expect { HasOffersV3::Offer.find_all_by_ids }.to raise_error ArgumentError
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.find_all_ids_by_advertiser_id' do
|
33
|
+
it 'should make a proper request call' do
|
34
|
+
stub_call
|
35
|
+
response = HasOffersV3::Offer.find_all_ids_by_advertiser_id advertiser_id: 1
|
36
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'findAllIdsByAdvertiserId', 'advertiser_id' => '1'})).should have_been_made
|
37
|
+
validate_call response
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when there is no id' do
|
41
|
+
it 'should raise exception' do
|
42
|
+
expect { HasOffersV3::Offer.find_all_ids_by_advertiser_id }.to raise_error ArgumentError
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.find_by_id' do
|
48
|
+
it 'should make a proper request call' do
|
49
|
+
stub_call
|
50
|
+
response = HasOffersV3::Offer.find_by_id id: 1
|
51
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'findById', 'id' => '1'})).should have_been_made
|
52
|
+
validate_call response
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when there is no id' do
|
56
|
+
it 'should raise exception' do
|
57
|
+
expect { HasOffersV3::Offer.find_by_id }.to raise_error ArgumentError
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '.get_groups' do
|
63
|
+
it 'should make a proper request call' do
|
64
|
+
stub_call
|
65
|
+
response = HasOffersV3::Offer.get_groups id: 1
|
66
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'getGroups'})).should have_been_made
|
67
|
+
validate_call response
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when there is no id' do
|
71
|
+
it 'should raise exception' do
|
72
|
+
expect { HasOffersV3::Offer.get_groups }.to raise_error ArgumentError
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HasOffersV3::Report do
|
4
|
+
subject { HasOffersV3::Report }
|
5
|
+
let(:url) { api_url 'Report' }
|
6
|
+
|
7
|
+
describe '.get_conversions' do
|
8
|
+
before(:each) { stub_call }
|
9
|
+
|
10
|
+
it 'should make a proper request call' do
|
11
|
+
response = subject.get_conversions
|
12
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'getConversions'})).should have_been_made
|
13
|
+
validate_call response
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.getConversions' do
|
18
|
+
before(:each) { stub_call }
|
19
|
+
|
20
|
+
it 'should make a proper request call' do
|
21
|
+
response = subject.getConversions
|
22
|
+
a_request(:post, url).with(body: hash_including({'Method' => 'getConversions'})).should have_been_made
|
23
|
+
validate_call response
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should show a deprecation warning' do
|
27
|
+
expect(subject).to receive(:deprecation).with('getConversions', 'get_conversions')
|
28
|
+
subject.getConversions
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should call find_all method' do
|
32
|
+
expect(subject).to receive(:get_conversions).with({test: 1})
|
33
|
+
subject.getConversions test: 1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.get_mod_summary_logs' do
|
38
|
+
let(:url) { Regexp.new api_url('Report') }
|
39
|
+
|
40
|
+
before(:each) { stub_call :get }
|
41
|
+
|
42
|
+
it 'should make a proper request call' do
|
43
|
+
response = subject.get_mod_summary_logs
|
44
|
+
a_request(:get, url).with(query: hash_including({'Method' => 'getModSummaryLogs'})).should have_been_made
|
45
|
+
validate_call response
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '.getModSummaryLogs' do
|
50
|
+
let(:url) { Regexp.new api_url('Report') }
|
51
|
+
|
52
|
+
before(:each) { stub_call :get }
|
53
|
+
|
54
|
+
it 'should make a proper request call' do
|
55
|
+
response = subject.getModSummaryLogs
|
56
|
+
a_request(:get, url).with(query: hash_including({'Method' => 'getModSummaryLogs'})).should have_been_made
|
57
|
+
validate_call response
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should show a deprecation warning' do
|
61
|
+
expect(subject).to receive(:deprecation).with('getModSummaryLogs', 'get_mod_summary_logs')
|
62
|
+
subject.getModSummaryLogs
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should call find_all method' do
|
66
|
+
expect(subject).to receive(:get_mod_summary_logs).with({test: 1})
|
67
|
+
subject.getModSummaryLogs test: 1
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
ENV['TEST'] = 'TEST'
|
2
|
+
|
3
|
+
require 'hasoffersv3'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
|
6
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
7
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
8
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
9
|
+
# loaded once.
|
10
|
+
#
|
11
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.filter_run :focus
|
16
|
+
|
17
|
+
# Run specs in random order to surface order dependencies. If you find an
|
18
|
+
# order dependency and want to debug it, you can fix the order by providing
|
19
|
+
# the seed, which is printed after each run.
|
20
|
+
# --seed 1234
|
21
|
+
config.order = 'random'
|
22
|
+
|
23
|
+
config.before :each do
|
24
|
+
WebMock.disable_net_connect!
|
25
|
+
HasOffersV3::Testing.disable!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def api_url(object)
|
30
|
+
"#{ HasOffersV3.configuration.base_uri }/#{ object }.json"
|
31
|
+
end
|
32
|
+
|
33
|
+
def body
|
34
|
+
{ 'response' => { 'status' => 1, 'data' => [] } }
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_return
|
38
|
+
{ status: 200, body: Oj.dump(body) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def data
|
42
|
+
body['response']['data']
|
43
|
+
end
|
44
|
+
|
45
|
+
def stub_call(method = :post, to_return = nil, custom_url = nil)
|
46
|
+
stub_request(method, custom_url || url).to_return to_return || default_return
|
47
|
+
end
|
48
|
+
|
49
|
+
def validate_call(response)
|
50
|
+
expect(response).to be_success
|
51
|
+
expect(response.data).to be == data
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hasoffersv3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maximilian Seifert
|
8
|
+
- Timo Rößner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: oj
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activesupport
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: webmock
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bundler
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.3'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.3'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rake
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
description: REST Client for the HasOffers API, version 3.
|
99
|
+
email:
|
100
|
+
- ms@hitfox.com
|
101
|
+
- tr@hitfox.com
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- .gitignore
|
107
|
+
- .rspec
|
108
|
+
- .ruby-gemset
|
109
|
+
- .ruby-version
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- hasoffersv3.gemspec
|
115
|
+
- lib/hasoffersv3.rb
|
116
|
+
- lib/hasoffersv3/advertiser.rb
|
117
|
+
- lib/hasoffersv3/advertiser_user.rb
|
118
|
+
- lib/hasoffersv3/affiliate.rb
|
119
|
+
- lib/hasoffersv3/base.rb
|
120
|
+
- lib/hasoffersv3/configuration.rb
|
121
|
+
- lib/hasoffersv3/conversion.rb
|
122
|
+
- lib/hasoffersv3/offer.rb
|
123
|
+
- lib/hasoffersv3/raw_log.rb
|
124
|
+
- lib/hasoffersv3/report.rb
|
125
|
+
- lib/hasoffersv3/response.rb
|
126
|
+
- lib/hasoffersv3/testing.rb
|
127
|
+
- lib/hasoffersv3/version.rb
|
128
|
+
- spec/lib/advertiser_spec.rb
|
129
|
+
- spec/lib/advertiser_user_spec.rb
|
130
|
+
- spec/lib/affiliate_spec.rb
|
131
|
+
- spec/lib/base_spec.rb
|
132
|
+
- spec/lib/conversion_spec.rb
|
133
|
+
- spec/lib/offer_spec.rb
|
134
|
+
- spec/lib/report_spec.rb
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
homepage:
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.1.11
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: REST Client for the HasOffers API, version 3.
|
160
|
+
test_files:
|
161
|
+
- spec/lib/advertiser_spec.rb
|
162
|
+
- spec/lib/advertiser_user_spec.rb
|
163
|
+
- spec/lib/affiliate_spec.rb
|
164
|
+
- spec/lib/base_spec.rb
|
165
|
+
- spec/lib/conversion_spec.rb
|
166
|
+
- spec/lib/offer_spec.rb
|
167
|
+
- spec/lib/report_spec.rb
|
168
|
+
- spec/spec_helper.rb
|