zanoxrb 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +43 -0
- data/README.md +22 -0
- data/Rakefile +20 -0
- data/lib/zanox/api.rb +88 -0
- data/lib/zanox/exceptions/access_denied.rb +29 -0
- data/lib/zanox/exceptions/invalid_request.rb +29 -0
- data/lib/zanox/logger.rb +31 -0
- data/lib/zanox/response.rb +62 -0
- data/lib/zanox/session.rb +34 -0
- data/lib/zanox/version.rb +27 -0
- data/lib/zanox.rb +33 -0
- data/specs/products_spec.rb +28 -0
- data/specs/profiles_spec.rb +26 -0
- data/specs/program_application_spec.rb +18 -0
- data/specs/programs_spec.rb +19 -0
- data/specs/spec_helper.rb +6 -0
- data/zanoxrb.gemspec +21 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cb0e3c81b39e97f52e2e1db629b60ba632f9abcb
|
4
|
+
data.tar.gz: 159dbebcc514d393d43655cbf1cfd3e565b6253a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c3ad875d26619c956875c63b31421bbaaf3bd68f8dbeeed710d2fb0ad32a19ae10a5ae2a68ee726accea87f574fab1bbf9160e18e811b1e008a93802a3f97c3
|
7
|
+
data.tar.gz: 31d75ad5c119003e2cd8f4eac3b266067a5bf7d453f929505ec5bc9cb292402d817afe9766562ce87637b89e4b2e5f7fa76cfe9302d10fceb7bae5d4c09644c4
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
zanoxrb (0.1)
|
5
|
+
httparty (~> 0.13)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
httparty (0.13.5)
|
12
|
+
json (~> 1.8)
|
13
|
+
multi_xml (>= 0.5.2)
|
14
|
+
json (1.8.3)
|
15
|
+
multi_xml (0.5.5)
|
16
|
+
rake (10.4.2)
|
17
|
+
rspec (3.3.0)
|
18
|
+
rspec-core (~> 3.3.0)
|
19
|
+
rspec-expectations (~> 3.3.0)
|
20
|
+
rspec-mocks (~> 3.3.0)
|
21
|
+
rspec-collection_matchers (1.1.2)
|
22
|
+
rspec-expectations (>= 2.99.0.beta1)
|
23
|
+
rspec-core (3.3.1)
|
24
|
+
rspec-support (~> 3.3.0)
|
25
|
+
rspec-expectations (3.3.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.3.0)
|
28
|
+
rspec-mocks (3.3.1)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.3.0)
|
31
|
+
rspec-support (3.3.0)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
rake (~> 10.4)
|
38
|
+
rspec (~> 3.3)
|
39
|
+
rspec-collection_matchers (~> 1.1)
|
40
|
+
zanoxrb!
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.10.4
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
ZanoxRB [![Build Status](https://travis-ci.org/mozestudio/zanox-rb.svg)](https://travis-ci.org/mozestudio/zanox-rb)
|
2
|
+
=======
|
3
|
+
A Ruby wrapper for Zanox's RESTful APIs because all the current alternatives outta here are shit.
|
4
|
+
Currently supporting only `GET` requests (aka, read-only).
|
5
|
+
|
6
|
+
Install
|
7
|
+
=======
|
8
|
+
`$ gem install zanoxrb`
|
9
|
+
|
10
|
+
Usage
|
11
|
+
=====
|
12
|
+
To store the Zanox keys safely, consider to store them inside your environment variables:
|
13
|
+
```
|
14
|
+
$ export ZANOX_CONNECT_ID=''
|
15
|
+
$ export ZANOX_SECRET_KEY=''
|
16
|
+
```
|
17
|
+
|
18
|
+
To make requests to the APIs, call `Zanox::API#request` passing the endpoint of the method you want to call and optionally a hash with one or more params (such as `q`, `date`, `programs`, etc.) based on the official documentation you can find [here](https://developer.zanox.com/web/guest/publisher-api-2011/).
|
19
|
+
|
20
|
+
Every call will return a native Ruby hash or an array reflecting the original documentation provided by Zanox (I plan to also wrap every response inside a class that allows to get every value following the Ruby-way, btw).
|
21
|
+
|
22
|
+
For debugging purpose, consider also to enable info logs by executing `Zanox::API.debug!`.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
task default: [ :build, :install, :test ]
|
5
|
+
|
6
|
+
task :build do
|
7
|
+
`gem build zanoxrb.gemspec`
|
8
|
+
end
|
9
|
+
|
10
|
+
task :install do
|
11
|
+
`gem install *.gem`
|
12
|
+
end
|
13
|
+
|
14
|
+
task :test do
|
15
|
+
FileUtils.cd 'specs' do
|
16
|
+
Dir['*_spec.rb'].each do |spec|
|
17
|
+
sh "rspec #{spec} --backtrace --color --format doc -r ./spec_helper.rb"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/zanox/api.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright(C) 2015 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# THIS SOFTWARE IS PROVIDED BY Giovanni Capuano ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
11
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Giovanni Capuano OR
|
13
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
14
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
15
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
16
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
17
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
18
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
19
|
+
#
|
20
|
+
# The views and conclusions contained in the software and documentation are those of the
|
21
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
22
|
+
# or implied, of Giovanni Capuano.
|
23
|
+
#++
|
24
|
+
|
25
|
+
module Zanox
|
26
|
+
module API
|
27
|
+
include HTTParty
|
28
|
+
logger Logger.new
|
29
|
+
base_uri 'http://api.zanox.com'
|
30
|
+
|
31
|
+
class << self
|
32
|
+
attr_accessor :debug
|
33
|
+
|
34
|
+
def logger
|
35
|
+
@logger ||= Logger.new
|
36
|
+
end
|
37
|
+
|
38
|
+
def debug?
|
39
|
+
!!@debug
|
40
|
+
end
|
41
|
+
|
42
|
+
def debug!
|
43
|
+
@debug = true
|
44
|
+
end
|
45
|
+
|
46
|
+
def request(method, options = {}, headers = {})
|
47
|
+
if Session.secret_key
|
48
|
+
method_path = method[0] == '/' ? method : "/#{method}"
|
49
|
+
timestamp, nonce, signature = fingerprint_of(method_path, options)
|
50
|
+
headers.merge!({
|
51
|
+
'Authorization' => "ZXWS #{Session.connect_id}:#{signature}",
|
52
|
+
'Date' => timestamp,
|
53
|
+
'nonce' => nonce
|
54
|
+
})
|
55
|
+
else
|
56
|
+
options.merge!({ 'connectId' => Session.connect_id })
|
57
|
+
end
|
58
|
+
|
59
|
+
logger.info "Params: #{options.inspect}"
|
60
|
+
logger.info "Headers: #{headers.inspect}"
|
61
|
+
response = get("/json/2011-03-01/#{method}", query: options, headers: headers)
|
62
|
+
Response.new(response)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
def fingerprint_of(method, options, verb = 'GET')
|
67
|
+
timestamp = get_timestamp
|
68
|
+
nonce = get_nonce
|
69
|
+
params = ''#?' + URI.encode_www_form(options)
|
70
|
+
signature = create_signature(Session.secret_key, "#{verb}#{method.downcase}#{params}#{timestamp}#{nonce}")
|
71
|
+
[timestamp, nonce, signature]
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_timestamp
|
75
|
+
Time.now.strftime('%a, %e %b %Y %T %Z')
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_nonce
|
79
|
+
Digest::MD5.hexdigest((Time.new.usec + rand()).to_s)
|
80
|
+
end
|
81
|
+
|
82
|
+
def create_signature(secret_key, string_to_sign)
|
83
|
+
digest = OpenSSL::HMAC.digest('sha1', secret_key, string_to_sign)
|
84
|
+
Base64.encode64(digest)[0..-2]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright(C) 2015 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# THIS SOFTWARE IS PROVIDED BY Giovanni Capuano ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
11
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Giovanni Capuano OR
|
13
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
14
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
15
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
16
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
17
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
18
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
19
|
+
#
|
20
|
+
# The views and conclusions contained in the software and documentation are those of the
|
21
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
22
|
+
# or implied, of Giovanni Capuano.
|
23
|
+
#++
|
24
|
+
|
25
|
+
module Zanox
|
26
|
+
module API
|
27
|
+
class AccessDeniedError < StandardError; end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright(C) 2015 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# THIS SOFTWARE IS PROVIDED BY Giovanni Capuano ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
11
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Giovanni Capuano OR
|
13
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
14
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
15
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
16
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
17
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
18
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
19
|
+
#
|
20
|
+
# The views and conclusions contained in the software and documentation are those of the
|
21
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
22
|
+
# or implied, of Giovanni Capuano.
|
23
|
+
#++
|
24
|
+
|
25
|
+
module Zanox
|
26
|
+
module API
|
27
|
+
class InvalidRequestError < StandardError; end
|
28
|
+
end
|
29
|
+
end
|
data/lib/zanox/logger.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright(C) 2015 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# THIS SOFTWARE IS PROVIDED BY Giovanni Capuano ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
11
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Giovanni Capuano OR
|
13
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
14
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
15
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
16
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
17
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
18
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
19
|
+
#
|
20
|
+
# The views and conclusions contained in the software and documentation are those of the
|
21
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
22
|
+
# or implied, of Giovanni Capuano.
|
23
|
+
#++
|
24
|
+
|
25
|
+
module Zanox
|
26
|
+
class Logger
|
27
|
+
def method_missing(m, *args, &block)
|
28
|
+
puts "[ZANOX] #{args}" if Zanox::API::debug?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright(C) 2015 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# THIS SOFTWARE IS PROVIDED BY Giovanni Capuano ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
11
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Giovanni Capuano OR
|
13
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
14
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
15
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
16
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
17
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
18
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
19
|
+
#
|
20
|
+
# The views and conclusions contained in the software and documentation are those of the
|
21
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
22
|
+
# or implied, of Giovanni Capuano.
|
23
|
+
#++
|
24
|
+
|
25
|
+
module Zanox
|
26
|
+
class Response
|
27
|
+
attr_reader :response
|
28
|
+
|
29
|
+
def initialize(response)
|
30
|
+
@response = response
|
31
|
+
|
32
|
+
status_code = @response.parsed_response['code']
|
33
|
+
if status_code
|
34
|
+
if status_code >= 400 && status_code <= 499
|
35
|
+
raise API::AccessDeniedError, @response.parsed_response['message']
|
36
|
+
elsif status_code >= 100 && status_code <= 199
|
37
|
+
raise API::InvalidRequestError, @response.parsed_response['reason']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def response
|
43
|
+
@response.parsed_response
|
44
|
+
end
|
45
|
+
|
46
|
+
def inspect
|
47
|
+
response
|
48
|
+
end
|
49
|
+
|
50
|
+
def method_missing(m, *args, &block)
|
51
|
+
key = m.to_s
|
52
|
+
response = @response[key] || @response["@#{key}"] || @response[camelize(key)]
|
53
|
+
response.kind_of?(Hash) && response.length == 1 ? response.values.first : response
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def camelize(s)
|
58
|
+
words = s.split('_')
|
59
|
+
([words.first] + words.drop(1).map(&:capitalize!)).join
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright(C) 2015 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# THIS SOFTWARE IS PROVIDED BY Giovanni Capuano ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
11
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Giovanni Capuano OR
|
13
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
14
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
15
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
16
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
17
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
18
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
19
|
+
#
|
20
|
+
# The views and conclusions contained in the software and documentation are those of the
|
21
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
22
|
+
# or implied, of Giovanni Capuano.
|
23
|
+
#++
|
24
|
+
|
25
|
+
module Zanox
|
26
|
+
module API
|
27
|
+
module Session
|
28
|
+
class << self
|
29
|
+
attr_accessor :connect_id
|
30
|
+
attr_accessor :secret_key
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright(C) 2015 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# THIS SOFTWARE IS PROVIDED BY Giovanni Capuano ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
11
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Giovanni Capuano OR
|
13
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
14
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
15
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
16
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
17
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
18
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
19
|
+
#
|
20
|
+
# The views and conclusions contained in the software and documentation are those of the
|
21
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
22
|
+
# or implied, of Giovanni Capuano.
|
23
|
+
#++
|
24
|
+
|
25
|
+
module Zanox
|
26
|
+
VERSION = '0.1'
|
27
|
+
end
|
data/lib/zanox.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright(C) 2015 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# THIS SOFTWARE IS PROVIDED BY Giovanni Capuano ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
11
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Giovanni Capuano OR
|
13
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
14
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
15
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
16
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
17
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
18
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
19
|
+
#
|
20
|
+
# The views and conclusions contained in the software and documentation are those of the
|
21
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
22
|
+
# or implied, of Giovanni Capuano.
|
23
|
+
#++
|
24
|
+
require 'httparty'
|
25
|
+
require 'openssl'
|
26
|
+
|
27
|
+
require 'zanox/logger'
|
28
|
+
require 'zanox/session'
|
29
|
+
require 'zanox/exceptions/access_denied'
|
30
|
+
require 'zanox/exceptions/invalid_request'
|
31
|
+
require 'zanox/response'
|
32
|
+
require 'zanox/api'
|
33
|
+
require 'zanox/version'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
describe Zanox::API do
|
2
|
+
describe '#request' do
|
3
|
+
context 'products' do
|
4
|
+
let(:products) { Zanox::API.request('products', q: 'nike', programs: 7408) }
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Zanox::API::Session.connect_id = '43EEF0445509C7205827'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns pagination infos' do
|
11
|
+
expect(products.page).to be 0
|
12
|
+
expect(products.items).to be 10
|
13
|
+
expect(products.total).to be > 100
|
14
|
+
expect(products.query).to eq('nike')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns a list of products with given keyword and program' do
|
18
|
+
items = products.product_items
|
19
|
+
|
20
|
+
expect(items).to be_an(Array)
|
21
|
+
expect(items).to have_exactly(10).products
|
22
|
+
|
23
|
+
expect(items.all? { |i| i['name'] =~ /nike/i }).to be_truthy
|
24
|
+
expect(items.all? { |i| i['program']['@id'].to_i == 7408 }).to be_truthy
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
describe Zanox::API do
|
2
|
+
describe '#request' do
|
3
|
+
context 'profiles' do
|
4
|
+
let(:profiles) { Zanox::API.request('profiles').profile_item }
|
5
|
+
|
6
|
+
it 'returns a list of items' do
|
7
|
+
expect(profiles).to have_at_least(1).profile
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns a list of profiles with fields talking about the relative owner' do
|
11
|
+
profile = profiles.first
|
12
|
+
|
13
|
+
expect(profile['@id'].to_i).to be > 0
|
14
|
+
|
15
|
+
expect(profile['firstName']).to be_a(String)
|
16
|
+
expect(profile['firstName']).not_to be_empty
|
17
|
+
|
18
|
+
expect(profile['email']).to be_a(String)
|
19
|
+
expect(profile['email']).not_to be_empty
|
20
|
+
|
21
|
+
expect(profile['userName']).to be_a(String)
|
22
|
+
expect(profile['userName']).not_to be_empty
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
describe Zanox::API do
|
2
|
+
describe '#request' do
|
3
|
+
context 'program applications' do
|
4
|
+
let(:program_applications) { Zanox::API.request('programapplications') }
|
5
|
+
|
6
|
+
it 'returns pagination infos' do
|
7
|
+
expect(program_applications.page).to be 0
|
8
|
+
expect(program_applications.items).to be > 0
|
9
|
+
expect(program_applications.total).to be > 0
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns the list of your program applications' do
|
13
|
+
program_application = program_applications.program_application_items
|
14
|
+
expect(program_application).to be_an(Array)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe Zanox::API do
|
2
|
+
describe '#request' do
|
3
|
+
context 'programs' do
|
4
|
+
let(:programs) { Zanox::API.request('programs') }
|
5
|
+
|
6
|
+
it 'returns pagination infos' do
|
7
|
+
expect(programs.page).to be 0
|
8
|
+
expect(programs.items).to be 10
|
9
|
+
expect(programs.total).to be > 1000
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns a list of programs' do
|
13
|
+
items = programs.program_items
|
14
|
+
expect(items).to be_an(Array)
|
15
|
+
expect(items).to have_exactly(10).programs
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/zanoxrb.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Kernel.load 'lib/zanox/version.rb'
|
2
|
+
|
3
|
+
Gem::Specification.new { |s|
|
4
|
+
s.name = 'zanoxrb'
|
5
|
+
s.version = Zanox::VERSION
|
6
|
+
s.author = 'Giovanni Capuano'
|
7
|
+
s.email = 'webmaster@giovannicapuano.net'
|
8
|
+
s.homepage = 'http://github.com/mozestudio/zanoxrb'
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.summary = "A Ruby wrapper for Zanox's RESTful APIs."
|
11
|
+
s.description = "A Ruby wrapper for Zanox's RESTful APIs because all the current alternatives outta here are shit."
|
12
|
+
s.license = 'BSD'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.require_paths = ['lib']
|
16
|
+
|
17
|
+
s.add_dependency 'httparty', '~> 0.13'
|
18
|
+
s.add_development_dependency 'rake', '~> 10.4'
|
19
|
+
s.add_development_dependency 'rspec', '~> 3.3'
|
20
|
+
s.add_development_dependency 'rspec-collection_matchers', '~> 1.1'
|
21
|
+
}
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zanoxrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Giovanni Capuano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
version_requirements: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0.13'
|
19
|
+
name: httparty
|
20
|
+
prerelease: false
|
21
|
+
requirement: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0.13'
|
26
|
+
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '10.4'
|
33
|
+
name: rake
|
34
|
+
prerelease: false
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '10.4'
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.3'
|
47
|
+
name: rspec
|
48
|
+
prerelease: false
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.3'
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.1'
|
61
|
+
name: rspec-collection_matchers
|
62
|
+
prerelease: false
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.1'
|
68
|
+
type: :development
|
69
|
+
description: A Ruby wrapper for Zanox's RESTful APIs because all the current alternatives
|
70
|
+
outta here are shit.
|
71
|
+
email: webmaster@giovannicapuano.net
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/zanox.rb
|
83
|
+
- lib/zanox/api.rb
|
84
|
+
- lib/zanox/exceptions/access_denied.rb
|
85
|
+
- lib/zanox/exceptions/invalid_request.rb
|
86
|
+
- lib/zanox/logger.rb
|
87
|
+
- lib/zanox/response.rb
|
88
|
+
- lib/zanox/session.rb
|
89
|
+
- lib/zanox/version.rb
|
90
|
+
- specs/products_spec.rb
|
91
|
+
- specs/profiles_spec.rb
|
92
|
+
- specs/program_application_spec.rb
|
93
|
+
- specs/programs_spec.rb
|
94
|
+
- specs/spec_helper.rb
|
95
|
+
- zanoxrb.gemspec
|
96
|
+
homepage: http://github.com/mozestudio/zanoxrb
|
97
|
+
licenses:
|
98
|
+
- BSD
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.8
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: A Ruby wrapper for Zanox's RESTful APIs.
|
120
|
+
test_files: []
|