zookal_magento_rest_api 0.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 +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +82 -0
- data/Rakefile +7 -0
- data/lib/zookal_magento_rest_api/version.rb +3 -0
- data/lib/zookal_magento_rest_api.rb +144 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/zookal_magento_rest_api_spec.rb +188 -0
- data/zookal-magento-rest-api/.gitignore +22 -0
- data/zookal-magento-rest-api/Gemfile +4 -0
- data/zookal-magento-rest-api/LICENSE.txt +22 -0
- data/zookal-magento-rest-api/README.md +29 -0
- data/zookal-magento-rest-api/Rakefile +2 -0
- data/zookal-magento-rest-api/lib/zookal/magento/rest/api/version.rb +9 -0
- data/zookal-magento-rest-api/lib/zookal/magento/rest/api.rb +11 -0
- data/zookal-magento-rest-api/zookal-magento-rest-api.gemspec +23 -0
- data/zookal_magento_rest_api.gemspec +29 -0
- metadata +163 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bf6d8162f9afab5ccd2ded8c08185cb69f4947bc
|
4
|
+
data.tar.gz: 138417e1bf08fbfda6f85fbeac1f2eba8d7a4052
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2c0443d11fac83e0af948f798c28466468a6f42f56891ec3589aa0b61525f5a46030bc23d433c46404f3e2d1399cff4c942c5db0271873ef9fb45fdd8c22dc7c
|
7
|
+
data.tar.gz: 913e5ab08f2a9c5e94ef11da5ffd0b514a8f988c9867de497b1d8484f8ea207fee42e0371b61e0b0e1c2c2b27283b76d1ad9bd0bd31fd9b6fd2ac0e5cb677ebb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Michael Imstepf
|
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,82 @@
|
|
1
|
+
# ZookalMagentoRestApi
|
2
|
+
|
3
|
+
Ruby wrapper for backend calls to Zookal's Magento store. Prior authentication & authorization (through oAuth) required.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'zookal_magento_rest_api'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install zookal_magento_rest_api
|
18
|
+
|
19
|
+
## Setup
|
20
|
+
|
21
|
+
Create a file `config/initializers/zookal_magento_rest_api.rb` with the following content and restart Rails after saving the file:
|
22
|
+
|
23
|
+
ZookalMagentoRestApi.configure do |config|
|
24
|
+
config.consumer_key = "123dsfdsafQ231" # from Magento Admin panel
|
25
|
+
config.consumer_secret = "23dfsfFdsfsdee" # from Magento Admin panel
|
26
|
+
config.site = "https://www.zookal.com" # without trailing slash and no redirects (e.g. root domain to www)
|
27
|
+
config.access_key = "3434412373rf" # from prior authentication
|
28
|
+
config.access_secret = "df23sdfsf23a" # from prior authentication
|
29
|
+
config.url_params = "utm_source=some-company&utm_medium=affiliate&utm_campaign=newsletter-01-2014" # optional
|
30
|
+
end
|
31
|
+
|
32
|
+
*Important*: Make sure the URL in the site configuration is without trailing slash and has no redirect (e.g. `https://zookal.com` redirects to `https://www.zookal.com`). Otherwise you'll get a 301 Redirect error for each request.
|
33
|
+
|
34
|
+
Information on how to obtain access_key and access_secret can be seen [here](https://github.com/necrodome/magento-rails-rest-access-sample/blob/master/app/controllers/products_controller.rb)
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
Instantiate a client
|
39
|
+
|
40
|
+
zookal_magento_client = ZookalMagentoRestApi::Client.new
|
41
|
+
|
42
|
+
Query a book
|
43
|
+
|
44
|
+
book_buy_new = zookal_magento_client.find_by(isbn: 9781442531109, purchase_type: "Buy New")
|
45
|
+
book_rent = zookal_magento_client.find_by(isbn: 9781442531109, purchase_type: "Rent")
|
46
|
+
|
47
|
+
Check if a book exists
|
48
|
+
|
49
|
+
book_buy_new.present?
|
50
|
+
|
51
|
+
Get attributes
|
52
|
+
|
53
|
+
```
|
54
|
+
book_buy_new.url_with_params # Full URL with specified params in `config/zookal_magento_rest_api.rb`
|
55
|
+
book_buy_new.special_price # Price
|
56
|
+
book_buy_new.price # RRP
|
57
|
+
book_buy_new.author # Author
|
58
|
+
book_buy_new.sku # SKU
|
59
|
+
book_buy_new.name # Name
|
60
|
+
book_buy_new.edition # Edition
|
61
|
+
book_buy_new.publisher # Publisher
|
62
|
+
book_buy_new.year # Year
|
63
|
+
book_buy_new.pages # Pages
|
64
|
+
```
|
65
|
+
|
66
|
+
Get list of all attributes in console
|
67
|
+
|
68
|
+
$ book_buy_new.instance_variable_get("@table")
|
69
|
+
|
70
|
+
Debugging
|
71
|
+
|
72
|
+
book_buy_new.meta_status # HTTP status code, 200 for successful request, 4xx for client error, 5xx for server error
|
73
|
+
book_buy_new.meta_message # HTTP status message, e.g. "OK" for 200 or "Unauthorized" for 401
|
74
|
+
book_buy_new.meta_errors # Array of detailed error messages, e.g. ["Invalid value for attribute purchase_type", "config.access_secret not specified in initializer file"]
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
1. Fork it ( http://github.com/<my-github-username>/zookal-magento-rest-api/fork )
|
79
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
80
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
81
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
82
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
require "zookal_magento_rest_api/version"
|
2
|
+
|
3
|
+
module ZookalMagentoRestApi
|
4
|
+
class << self
|
5
|
+
attr_accessor :consumer_key, :consumer_secret, :site, :access_key, :access_secret, :url_params
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configure(&block)
|
9
|
+
yield self
|
10
|
+
end
|
11
|
+
|
12
|
+
class Client
|
13
|
+
require "oauth"
|
14
|
+
require "multi_json"
|
15
|
+
require "ostruct"
|
16
|
+
|
17
|
+
def find_by(opts)
|
18
|
+
@access_token ||= prepare_access_token
|
19
|
+
|
20
|
+
purchase_type_id = translate_purchase_type_to_purchase_type_id(opts[:purchase_type])
|
21
|
+
|
22
|
+
# rescue in case a configuration setting is missing, which will crash OAuth
|
23
|
+
response = @access_token.get("/api/rest/products?filter[1][attribute]=isbn&filter[1][eq]=#{opts[:isbn]}&filter[2][attribute]=purchase_type&filter[2][eq]=#{purchase_type_id}&filter[3][attribute]=status&filter[3][eq]=1") rescue nil
|
24
|
+
response_status = response.code.to_i rescue nil
|
25
|
+
response_message = response.message rescue nil
|
26
|
+
# decode response body and rescue if there's a ParseError (e.g. when Magento returns HTML after invalid authentication)
|
27
|
+
if response
|
28
|
+
begin
|
29
|
+
response_body_decoded = MultiJson.decode(response.body)
|
30
|
+
rescue MultiJson::ParseError => exception
|
31
|
+
puts "MultiJson::ParseError"
|
32
|
+
puts exception
|
33
|
+
response_body_decoded = nil
|
34
|
+
end
|
35
|
+
else
|
36
|
+
response_body_decoded = nil
|
37
|
+
end
|
38
|
+
response_o_auth_error_message = get_oauth_error_message(response_body_decoded)
|
39
|
+
|
40
|
+
attributes = get_book_attributes(response_body_decoded)
|
41
|
+
entity_id = get_entity_id(attributes, response_body_decoded)
|
42
|
+
|
43
|
+
attributes[:meta_status] = response_status if response_status
|
44
|
+
attributes[:meta_message] = response_message if response_message
|
45
|
+
errors = get_errors(opts, purchase_type_id, response_o_auth_error_message)
|
46
|
+
attributes[:meta_errors] = errors if errors
|
47
|
+
|
48
|
+
attributes[:present?] = is_book_present?(attributes)
|
49
|
+
url_with_params = get_url_with_params(attributes, entity_id)
|
50
|
+
attributes[:url_with_params] = url_with_params if url_with_params
|
51
|
+
|
52
|
+
OpenStruct.new(attributes)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def prepare_access_token
|
58
|
+
consumer = OAuth::Consumer.new(ZookalMagentoRestApi.consumer_key, ZookalMagentoRestApi.consumer_secret, :site => ZookalMagentoRestApi.site)
|
59
|
+
token_hash = {oauth_token: ZookalMagentoRestApi.access_key, oauth_token_secret: ZookalMagentoRestApi.access_secret}
|
60
|
+
access_token = OAuth::AccessToken.from_hash(consumer, token_hash)
|
61
|
+
end
|
62
|
+
|
63
|
+
def translate_purchase_type_to_purchase_type_id(purchase_type)
|
64
|
+
return nil unless purchase_type.is_a? String
|
65
|
+
case purchase_type.downcase
|
66
|
+
when "buy new" then 56
|
67
|
+
when "rent" then 55
|
68
|
+
else return nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_oauth_error_message(response_body_decoded)
|
73
|
+
response_body_decoded["messages"]["error"].first["message"] rescue nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_book_attributes(response_body_decoded)
|
77
|
+
sku = response_body_decoded.values.first["sku"] rescue nil
|
78
|
+
sku ? response_body_decoded.values.first : {}
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_entity_id(attributes, response_body_decoded)
|
82
|
+
return nil unless attributes.any?
|
83
|
+
response_body_decoded.keys.first
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_errors(opts, purchase_type_id, response_o_auth_error_message)
|
87
|
+
errors = []
|
88
|
+
|
89
|
+
unless ZookalMagentoRestApi.consumer_key
|
90
|
+
errors << "config.consumer_key not specified in initializer file"
|
91
|
+
end
|
92
|
+
|
93
|
+
unless ZookalMagentoRestApi.consumer_secret
|
94
|
+
errors << "config.consumer_secret not specified in initializer file"
|
95
|
+
end
|
96
|
+
|
97
|
+
unless ZookalMagentoRestApi.site
|
98
|
+
errors << "config.site not specified in initializer file"
|
99
|
+
end
|
100
|
+
|
101
|
+
unless ZookalMagentoRestApi.access_key
|
102
|
+
errors << "config.access_key not specified in initializer file"
|
103
|
+
end
|
104
|
+
|
105
|
+
unless ZookalMagentoRestApi.access_secret
|
106
|
+
errors << "config.access_secret not specified in initializer file"
|
107
|
+
end
|
108
|
+
|
109
|
+
unless opts.has_key?(:isbn)
|
110
|
+
errors << "Attribute isbn not specified"
|
111
|
+
end
|
112
|
+
|
113
|
+
unless opts.has_key?(:purchase_type)
|
114
|
+
errors << "Attribute purchase_type not specified"
|
115
|
+
end
|
116
|
+
|
117
|
+
unless purchase_type_id
|
118
|
+
errors << "Invalid value for attribute purchase_type"
|
119
|
+
end
|
120
|
+
|
121
|
+
if response_o_auth_error_message
|
122
|
+
errors << response_o_auth_error_message
|
123
|
+
end
|
124
|
+
|
125
|
+
errors.any? ? errors : nil
|
126
|
+
end
|
127
|
+
|
128
|
+
def is_book_present?(attributes)
|
129
|
+
attributes["sku"] ? true : false
|
130
|
+
end
|
131
|
+
|
132
|
+
def get_url_with_params(attributes, entity_id)
|
133
|
+
return nil unless ZookalMagentoRestApi.site && attributes["url_key"] && entity_id
|
134
|
+
|
135
|
+
url = "#{ZookalMagentoRestApi.site}/catalog/product/view/id/#{entity_id}"
|
136
|
+
if ZookalMagentoRestApi.url_params
|
137
|
+
url = url + "?#{ZookalMagentoRestApi.url_params}"
|
138
|
+
end
|
139
|
+
|
140
|
+
url
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# ENV["RAILS_ENV"] ||= 'test'
|
2
|
+
require "zookal_magento_rest_api"
|
3
|
+
require "pry"
|
4
|
+
require "webmock/rspec"
|
5
|
+
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
# Run specs in random order to surface order dependencies. If you find an
|
9
|
+
# order dependency and want to debug it, you can fix the order by providing
|
10
|
+
# the seed, which is printed after each run.
|
11
|
+
# --seed 1234
|
12
|
+
config.order = "random"
|
13
|
+
|
14
|
+
# when a focus tag is present in RSpec, only run tests with focus tag: http://railscasts.com/episodes/285-spork
|
15
|
+
config.filter_run :focus => true
|
16
|
+
config.run_all_when_everything_filtered = true
|
17
|
+
end
|
18
|
+
|
19
|
+
# http://stackoverflow.com/questions/19075907/clean-solution-for-resetting-class-variables-in-between-rspec-tests/19079701#19079701
|
20
|
+
def reset_class_variables(cl)
|
21
|
+
cl.class_variables.each do |var|
|
22
|
+
cl.class_variable_set var, nil
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ZookalMagentoRestApi::Client do
|
4
|
+
response_body_book_buy_new = "{\"2378\":{\"status\":\"1\", \"sku\":\"978123432423\", \"url_key\":\"marketing-and-the-law\"}}"
|
5
|
+
response_body_unauthorized = "{\"messages\":{\"error\":[{\"code\":401,\"message\":\"oauth_problem=consumer_key_rejected\"}]}}"
|
6
|
+
after(:each) do
|
7
|
+
reset_class_variables ZookalMagentoRestApi
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when a configuration attribute is missing in the initializer file" do
|
11
|
+
it "set the correct attributes" do
|
12
|
+
ZookalMagentoRestApi.consumer_key = nil
|
13
|
+
ZookalMagentoRestApi.consumer_secret = "secret"
|
14
|
+
ZookalMagentoRestApi.site = "https://www.zookal.com"
|
15
|
+
ZookalMagentoRestApi.access_key = "key"
|
16
|
+
ZookalMagentoRestApi.access_secret = "secret"
|
17
|
+
|
18
|
+
magento_client = ZookalMagentoRestApi::Client.new
|
19
|
+
|
20
|
+
WebMock.stub_request(:get, "https://www.zookal.com/api/rest/products?filter[1][attribute]=isbn&filter[1][eq]=123&filter[2][attribute]=purchase_type&filter[2][eq]=56&filter[3][attribute]=status&filter[3][eq]=1")
|
21
|
+
.to_return(:status => 401,
|
22
|
+
:body => response_body_unauthorized
|
23
|
+
)
|
24
|
+
book = magento_client.find_by(isbn: 123, purchase_type: "Buy New")
|
25
|
+
expect(book.meta_status).to eq 401
|
26
|
+
expect(book.meta_errors.count).to eq 2
|
27
|
+
expect(book.meta_errors.first).to eq "config.consumer_key not specified in initializer file"
|
28
|
+
expect(book.present?).to be_false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when two configuration attributes are missing in the initializer file" do
|
33
|
+
it "set the correct attributes" do
|
34
|
+
ZookalMagentoRestApi.consumer_key = nil
|
35
|
+
ZookalMagentoRestApi.consumer_secret = "secret"
|
36
|
+
ZookalMagentoRestApi.site = "https://www.zookal.com"
|
37
|
+
ZookalMagentoRestApi.access_key = nil
|
38
|
+
ZookalMagentoRestApi.access_secret = "secret"
|
39
|
+
|
40
|
+
magento_client = ZookalMagentoRestApi::Client.new
|
41
|
+
|
42
|
+
WebMock.stub_request(:get, "https://www.zookal.com/api/rest/products?filter[1][attribute]=isbn&filter[1][eq]=123&filter[2][attribute]=purchase_type&filter[2][eq]=56&filter[3][attribute]=status&filter[3][eq]=1")
|
43
|
+
.to_return(:status => 401,
|
44
|
+
:body => response_body_unauthorized
|
45
|
+
)
|
46
|
+
book = magento_client.find_by(isbn: 123, purchase_type: "Buy New")
|
47
|
+
expect(book.meta_status).to eq 401
|
48
|
+
expect(book.meta_errors.count).to eq 3
|
49
|
+
expect(book.meta_errors[0]).to eq "config.consumer_key not specified in initializer file"
|
50
|
+
expect(book.meta_errors[1]).to eq "config.access_key not specified in initializer file"
|
51
|
+
expect(book.present?).to be_false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when no book was found" do
|
56
|
+
it "set the correct attributes" do
|
57
|
+
ZookalMagentoRestApi.consumer_key = "key"
|
58
|
+
ZookalMagentoRestApi.consumer_secret = "secret"
|
59
|
+
ZookalMagentoRestApi.site = "https://www.zookal.com"
|
60
|
+
ZookalMagentoRestApi.access_key = "key"
|
61
|
+
ZookalMagentoRestApi.access_secret = "secret"
|
62
|
+
|
63
|
+
magento_client = ZookalMagentoRestApi::Client.new
|
64
|
+
|
65
|
+
WebMock.stub_request(:get, "https://www.zookal.com/api/rest/products?filter[1][attribute]=isbn&filter[1][eq]=123&filter[2][attribute]=purchase_type&filter[2][eq]=56&filter[3][attribute]=status&filter[3][eq]=1")
|
66
|
+
.to_return(:status => 200,
|
67
|
+
:body => "[]"
|
68
|
+
)
|
69
|
+
book = magento_client.find_by(isbn: 123, purchase_type: "Buy New")
|
70
|
+
expect(book.meta_status).to eq 200
|
71
|
+
expect(book.meta_errors).to be_nil
|
72
|
+
expect(book.special_price).to be_nil
|
73
|
+
expect(book.present?).to be_false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when purchase_type was not specified" do
|
78
|
+
it "set the correct attributes" do
|
79
|
+
ZookalMagentoRestApi.consumer_key = "key"
|
80
|
+
ZookalMagentoRestApi.consumer_secret = "secret"
|
81
|
+
ZookalMagentoRestApi.site = "https://www.zookal.com"
|
82
|
+
ZookalMagentoRestApi.access_key = "key"
|
83
|
+
ZookalMagentoRestApi.access_secret = "secret"
|
84
|
+
|
85
|
+
magento_client = ZookalMagentoRestApi::Client.new
|
86
|
+
|
87
|
+
WebMock.stub_request(:get, "https://www.zookal.com/api/rest/products?filter[1][attribute]=isbn&filter[1][eq]=123&filter[2][attribute]=purchase_type&filter[2][eq]=&filter[3][attribute]=status&filter[3][eq]=1")
|
88
|
+
.to_return(:status => 200,
|
89
|
+
:body => response_body_book_buy_new
|
90
|
+
)
|
91
|
+
book = magento_client.find_by(isbn: 123)
|
92
|
+
expect(book.meta_status).to eq 200
|
93
|
+
expect(book.meta_errors.count).to eq 2
|
94
|
+
expect(book.meta_errors[0]).to eq "Attribute purchase_type not specified"
|
95
|
+
expect(book.present?).to be_true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when isbn was not specified" do
|
100
|
+
it "set the correct attributes" do
|
101
|
+
ZookalMagentoRestApi.consumer_key = "key"
|
102
|
+
ZookalMagentoRestApi.consumer_secret = "secret"
|
103
|
+
ZookalMagentoRestApi.site = "https://www.zookal.com"
|
104
|
+
ZookalMagentoRestApi.access_key = "key"
|
105
|
+
ZookalMagentoRestApi.access_secret = "secret"
|
106
|
+
|
107
|
+
magento_client = ZookalMagentoRestApi::Client.new
|
108
|
+
|
109
|
+
WebMock.stub_request(:get, "https://www.zookal.com/api/rest/products?filter[1][attribute]=isbn&filter[1][eq]=&filter[2][attribute]=purchase_type&filter[2][eq]=56&filter[3][attribute]=status&filter[3][eq]=1")
|
110
|
+
.to_return(:status => 200,
|
111
|
+
:body => response_body_book_buy_new
|
112
|
+
)
|
113
|
+
book = magento_client.find_by(purchase_type: "Buy New")
|
114
|
+
expect(book.meta_status).to eq 200
|
115
|
+
expect(book.meta_errors.count).to eq 1
|
116
|
+
expect(book.meta_errors[0]).to eq "Attribute isbn not specified"
|
117
|
+
expect(book.present?).to be_true
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when invalid purchase_type was entered" do
|
122
|
+
it "set the correct attributes" do
|
123
|
+
ZookalMagentoRestApi.consumer_key = "key"
|
124
|
+
ZookalMagentoRestApi.consumer_secret = "secret"
|
125
|
+
ZookalMagentoRestApi.site = "https://www.zookal.com"
|
126
|
+
ZookalMagentoRestApi.access_key = "key"
|
127
|
+
ZookalMagentoRestApi.access_secret = "secret"
|
128
|
+
|
129
|
+
magento_client = ZookalMagentoRestApi::Client.new
|
130
|
+
|
131
|
+
WebMock.stub_request(:get, "https://www.zookal.com/api/rest/products?filter[1][attribute]=isbn&filter[1][eq]=123&filter[2][attribute]=purchase_type&filter[2][eq]=&filter[3][attribute]=status&filter[3][eq]=1")
|
132
|
+
.to_return(:status => 200,
|
133
|
+
:body => response_body_book_buy_new
|
134
|
+
)
|
135
|
+
book = magento_client.find_by(isbn: 123, purchase_type: "Bbla")
|
136
|
+
expect(book.meta_status).to eq 200
|
137
|
+
expect(book.meta_errors.count).to eq 1
|
138
|
+
expect(book.meta_errors.first).to eq "Invalid value for attribute purchase_type"
|
139
|
+
expect(book.present?).to be_true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "when requested book was found and no url params exists" do
|
144
|
+
it "set the correct attributes" do
|
145
|
+
ZookalMagentoRestApi.consumer_key = "key"
|
146
|
+
ZookalMagentoRestApi.consumer_secret = "secret"
|
147
|
+
ZookalMagentoRestApi.site = "https://www.zookal.com"
|
148
|
+
ZookalMagentoRestApi.access_key = "key"
|
149
|
+
ZookalMagentoRestApi.access_secret = "secret"
|
150
|
+
ZookalMagentoRestApi.url_params = nil
|
151
|
+
|
152
|
+
magento_client = ZookalMagentoRestApi::Client.new
|
153
|
+
|
154
|
+
WebMock.stub_request(:get, "https://www.zookal.com/api/rest/products?filter[1][attribute]=isbn&filter[1][eq]=123&filter[2][attribute]=purchase_type&filter[2][eq]=56&filter[3][attribute]=status&filter[3][eq]=1")
|
155
|
+
.to_return(:status => 200,
|
156
|
+
:body => response_body_book_buy_new
|
157
|
+
)
|
158
|
+
book = magento_client.find_by(isbn: 123, purchase_type: "Buy New")
|
159
|
+
expect(book.meta_status).to eq 200
|
160
|
+
expect(book.meta_errors).to be_nil
|
161
|
+
expect(book.present?).to be_true
|
162
|
+
expect(book.url_with_params).to eq "https://www.zookal.com/catalog/product/view/id/2378"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "when requested book was found and url params exists" do
|
167
|
+
it "set the correct attributes" do
|
168
|
+
ZookalMagentoRestApi.consumer_key = "key"
|
169
|
+
ZookalMagentoRestApi.consumer_secret = "secret"
|
170
|
+
ZookalMagentoRestApi.site = "https://www.zookal.com"
|
171
|
+
ZookalMagentoRestApi.access_key = "key"
|
172
|
+
ZookalMagentoRestApi.access_secret = "secret"
|
173
|
+
ZookalMagentoRestApi.url_params = "utm_source=company&utm_medium=affiliate&utm_campaign=2014"
|
174
|
+
|
175
|
+
magento_client = ZookalMagentoRestApi::Client.new
|
176
|
+
|
177
|
+
WebMock.stub_request(:get, "https://www.zookal.com/api/rest/products?filter[1][attribute]=isbn&filter[1][eq]=123&filter[2][attribute]=purchase_type&filter[2][eq]=56&filter[3][attribute]=status&filter[3][eq]=1")
|
178
|
+
.to_return(:status => 200,
|
179
|
+
:body => response_body_book_buy_new
|
180
|
+
)
|
181
|
+
book = magento_client.find_by(isbn: 123, purchase_type: "Buy New")
|
182
|
+
expect(book.meta_status).to eq 200
|
183
|
+
expect(book.meta_errors).to be_nil
|
184
|
+
expect(book.present?).to be_true
|
185
|
+
expect(book.url_with_params).to eq "https://www.zookal.com/catalog/product/view/id/2378?utm_source=company&utm_medium=affiliate&utm_campaign=2014"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Michael Imstepf
|
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.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Zookal::Magento::Rest::Api
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'zookal-magento-rest-api'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install zookal-magento-rest-api
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/zookal-magento-rest-api/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zookal/magento/rest/api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zookal-magento-rest-api"
|
8
|
+
spec.version = Zookal::Magento::Rest::Api::VERSION
|
9
|
+
spec.authors = ["Michael Imstepf"]
|
10
|
+
spec.email = ["michael.imstepf@gmail.com"]
|
11
|
+
spec.summary = %q{TODO: Write a short summary. Required.}
|
12
|
+
spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zookal_magento_rest_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zookal_magento_rest_api"
|
8
|
+
spec.version = ZookalMagentoRestApi::VERSION
|
9
|
+
spec.authors = ["Michael Imstepf"]
|
10
|
+
spec.email = ["michael.imstepf@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby wrapper for the Zookal Magento REST API}
|
12
|
+
spec.description = %q{Gem to do backend REST API calls to Zookal's Magento store. Prior authentication (through oAuth) required.}
|
13
|
+
spec.homepage = "https://github.com/Zookal/zookal-magento-rest-api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "oauth"
|
22
|
+
spec.add_dependency "multi_json"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "webmock"
|
28
|
+
spec.add_development_dependency "pry"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zookal_magento_rest_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Imstepf
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Gem to do backend REST API calls to Zookal's Magento store. Prior authentication
|
112
|
+
(through oAuth) required.
|
113
|
+
email:
|
114
|
+
- michael.imstepf@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/zookal_magento_rest_api.rb
|
125
|
+
- lib/zookal_magento_rest_api/version.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- spec/zookal_magento_rest_api_spec.rb
|
128
|
+
- zookal-magento-rest-api/.gitignore
|
129
|
+
- zookal-magento-rest-api/Gemfile
|
130
|
+
- zookal-magento-rest-api/LICENSE.txt
|
131
|
+
- zookal-magento-rest-api/README.md
|
132
|
+
- zookal-magento-rest-api/Rakefile
|
133
|
+
- zookal-magento-rest-api/lib/zookal/magento/rest/api.rb
|
134
|
+
- zookal-magento-rest-api/lib/zookal/magento/rest/api/version.rb
|
135
|
+
- zookal-magento-rest-api/zookal-magento-rest-api.gemspec
|
136
|
+
- zookal_magento_rest_api.gemspec
|
137
|
+
homepage: https://github.com/Zookal/zookal-magento-rest-api
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata: {}
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 2.2.2
|
158
|
+
signing_key:
|
159
|
+
specification_version: 4
|
160
|
+
summary: Ruby wrapper for the Zookal Magento REST API
|
161
|
+
test_files:
|
162
|
+
- spec/spec_helper.rb
|
163
|
+
- spec/zookal_magento_rest_api_spec.rb
|