seoshop-api 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -3
- data/.travis.yml +12 -0
- data/Rakefile +2 -0
- data/lib/seoshop-api/client.rb +2 -2
- data/lib/seoshop-api/core/response_parser.rb +8 -77
- data/lib/seoshop-api/version.rb +1 -1
- data/seoshop-api.gemspec +6 -6
- metadata +18 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cefc1453a78871c993ff68e3946754aa8a97dd0
|
4
|
+
data.tar.gz: af5617ab1bd6606543c6219dbcd9389a1c2f91a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b73b2065d3667b1c2d103fbd54c3c0108e43c0d11a2b2bae9e85b3d8e0636bfa704269614f1914788a94d6d868e8327751bf4d454dd79d8f6b49002a98e398a8
|
7
|
+
data.tar.gz: 520642d15292a5319e08f4fbdd7c8a22b9f3de53110b8836b981216e1e5ad8e47952a6e22f63ca30aeb4c635a3018d7d11db59aa766983ca0c7e890dec55c9a7
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.2
|
4
|
+
- 2.3
|
5
|
+
deploy:
|
6
|
+
provider: rubygems
|
7
|
+
api_key:
|
8
|
+
secure: Ub9rAJHJeLuFmi6MO/TA71cL9zRWW++rXhACeho+KZGJfn9XGrQD6wVhQJtEUlag0M+LzgWeAiorPK66oSM2ZLNkmHyyajoh9uwv6J6G2IZ+sbC3NqvmEAWltvy1JU4ElZKY3aVRLAL/1CTtvrmS1Fjv5gPKizW3FrBTIFlXMVg=
|
9
|
+
gem: seoshop-api
|
10
|
+
on:
|
11
|
+
branch: master
|
12
|
+
repo: YotpoLtd/seoshop-api
|
data/Rakefile
CHANGED
data/lib/seoshop-api/client.rb
CHANGED
@@ -155,8 +155,8 @@ module Seoshop
|
|
155
155
|
conn.response :rashify
|
156
156
|
|
157
157
|
# Setting request and response to use JSON/XML
|
158
|
-
conn.request :
|
159
|
-
conn.response :
|
158
|
+
conn.request :multi_json
|
159
|
+
conn.response :multi_json
|
160
160
|
|
161
161
|
# Set to use instrumentals to get time logs
|
162
162
|
conn.use :instrumentation
|
@@ -10,96 +10,27 @@ module Seoshop
|
|
10
10
|
if env[:status] == 200
|
11
11
|
body = env[:response].body.response || env[:response].body
|
12
12
|
elsif env[:status] == 401
|
13
|
-
raise
|
13
|
+
raise HTTPUnauthorized.new 'invalid Seoshop credentials'
|
14
14
|
elsif env[:status] == 403
|
15
|
-
raise
|
15
|
+
raise HTTPForbidden.new env[:response].body.message
|
16
16
|
elsif env[:status] == 404
|
17
|
-
raise
|
17
|
+
raise HTTPNotFound.new env[:response].body.message
|
18
18
|
elsif env[:status] == 429
|
19
19
|
rate_limits = env[:response_headers]['X-RateLimit-Remaining'].split('/')
|
20
20
|
rate_limits_reset = env[:response_headers]['X-RateLimit-Reset'].split('/')
|
21
21
|
seconds = rate_limits_reset[0] if rate_limits[0] == '-1'
|
22
22
|
seconds = rate_limits_reset[1] if rate_limits[1] == '-1'
|
23
23
|
seconds = rate_limits_reset[2] if rate_limits[2] == '-1'
|
24
|
-
raise
|
24
|
+
raise RateLimit.new "RateLimit reset in #{seconds} seconds"
|
25
25
|
elsif env[:response] && env[:response].body && env[:response].body.status
|
26
26
|
body = env[:response].body.status
|
27
27
|
end
|
28
28
|
env[:body] = body
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
#
|
36
|
-
class ParseOj < FaradayMiddleware::ResponseMiddleware
|
37
|
-
dependency do
|
38
|
-
require 'oj' unless defined?(::Oj)
|
39
|
-
end
|
40
|
-
|
41
|
-
define_parser do |body|
|
42
|
-
begin
|
43
|
-
::Oj.load(body, mode: :compat) unless body.strip.empty?
|
44
|
-
rescue Oj::ParseError => e
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Request middleware that encodes the body as JSON.
|
50
|
-
#
|
51
|
-
# Processes only requests with matching Content-type or those without a type.
|
52
|
-
# If a request doesn't have a type but has a body, it sets the Content-type
|
53
|
-
# to JSON MIME-type.
|
54
|
-
#
|
55
|
-
# Doesn't try to encode bodies that already are in string form.
|
56
|
-
class EncodeOj < Faraday::Middleware
|
57
|
-
CONTENT_TYPE = 'Content-Type'.freeze
|
58
|
-
MIME_TYPE = 'application/json'.freeze
|
59
|
-
|
60
|
-
dependency do
|
61
|
-
require 'oj' unless defined?(::Oj)
|
62
|
-
end
|
63
|
-
|
64
|
-
def call(env)
|
65
|
-
match_content_type(env) do |data|
|
66
|
-
env[:body] = encode data
|
67
|
-
end
|
68
|
-
@app.call env
|
69
|
-
end
|
70
|
-
|
71
|
-
def encode(data)
|
72
|
-
::Oj.dump data
|
73
|
-
end
|
74
|
-
|
75
|
-
def match_content_type(env)
|
76
|
-
if process_request?(env)
|
77
|
-
env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE
|
78
|
-
yield env[:body] unless env[:body].respond_to?(:to_str)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def process_request?(env)
|
83
|
-
type = request_type(env)
|
84
|
-
has_body?(env) and (type.empty? or type == MIME_TYPE)
|
85
|
-
end
|
86
|
-
|
87
|
-
def has_body?(env)
|
88
|
-
body = env[:body] and !(body.respond_to?(:to_str) and body.empty?)
|
89
|
-
end
|
90
|
-
|
91
|
-
def request_type(env)
|
92
|
-
type = env[:request_headers][CONTENT_TYPE].to_s
|
93
|
-
type = type.split(';', 2).first if type.index(';')
|
94
|
-
type
|
95
|
-
end
|
96
|
-
|
97
|
-
class Seoshop::ResponseParser::RateLimit < Exception; end
|
98
|
-
class Seoshop::ResponseParser::HTTPForbidden < Exception; end
|
99
|
-
class Seoshop::ResponseParser::HTTPUnauthorized < Exception; end
|
100
|
-
class Seoshop::ResponseParser::HTTPNotFound < Exception; end
|
31
|
+
class RateLimit < Exception; end
|
32
|
+
class HTTPForbidden < Exception; end
|
33
|
+
class HTTPUnauthorized < Exception; end
|
34
|
+
class HTTPNotFound < Exception; end
|
101
35
|
end
|
102
36
|
end
|
103
|
-
|
104
|
-
Faraday.register_middleware :response, oj: Seoshop::ParseOj
|
105
|
-
Faraday.register_middleware :request, oj: Seoshop::EncodeOj
|
data/lib/seoshop-api/version.rb
CHANGED
data/seoshop-api.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'seoshop-api/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "seoshop-api"
|
8
8
|
spec.version = Seoshop::VERSION
|
9
|
-
spec.authors = ["Nimrod Popper"]
|
10
|
-
spec.email = ["nimrod@yotpo.com"]
|
9
|
+
spec.authors = ["Nimrod Popper", "Vladislav Shub"]
|
10
|
+
spec.email = ["nimrod@yotpo.com", "vlad@yotpo.com"]
|
11
11
|
spec.description = %q{Ruby wrapper for SEOshop API - written by Yotpo}
|
12
12
|
spec.summary = %q{Ruby wrapper for SEOshop API - written by Yotpo}
|
13
13
|
spec.homepage = "https://github.com/YotpoLtd/seoshop-api"
|
@@ -18,14 +18,14 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.
|
22
|
-
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
23
|
|
24
24
|
spec.add_dependency 'oauth2'
|
25
25
|
spec.add_dependency 'faraday'
|
26
26
|
spec.add_dependency 'typhoeus'
|
27
|
-
spec.add_dependency 'faraday_middleware'
|
27
|
+
spec.add_dependency 'faraday_middleware'
|
28
|
+
spec.add_dependency 'faraday_middleware-multi_json'
|
28
29
|
spec.add_dependency 'rash'
|
29
|
-
spec.add_dependency 'oj'
|
30
30
|
spec.add_dependency 'activesupport'
|
31
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seoshop-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nimrod Popper
|
8
|
+
- Vladislav Shub
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2017-04-12 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -16,28 +17,28 @@ dependencies:
|
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
20
|
+
version: '1.14'
|
20
21
|
type: :development
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
27
|
+
version: '1.14'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: rake
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- - "
|
32
|
+
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
+
version: '10.0'
|
34
35
|
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- - "
|
39
|
+
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
+
version: '10.0'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: oauth2
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,18 +85,18 @@ dependencies:
|
|
84
85
|
name: faraday_middleware
|
85
86
|
requirement: !ruby/object:Gem::Requirement
|
86
87
|
requirements:
|
87
|
-
- - "
|
88
|
+
- - ">="
|
88
89
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0
|
90
|
+
version: '0'
|
90
91
|
type: :runtime
|
91
92
|
prerelease: false
|
92
93
|
version_requirements: !ruby/object:Gem::Requirement
|
93
94
|
requirements:
|
94
|
-
- - "
|
95
|
+
- - ">="
|
95
96
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0
|
97
|
+
version: '0'
|
97
98
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
99
|
+
name: faraday_middleware-multi_json
|
99
100
|
requirement: !ruby/object:Gem::Requirement
|
100
101
|
requirements:
|
101
102
|
- - ">="
|
@@ -109,7 +110,7 @@ dependencies:
|
|
109
110
|
- !ruby/object:Gem::Version
|
110
111
|
version: '0'
|
111
112
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
113
|
+
name: rash
|
113
114
|
requirement: !ruby/object:Gem::Requirement
|
114
115
|
requirements:
|
115
116
|
- - ">="
|
@@ -139,11 +140,13 @@ dependencies:
|
|
139
140
|
description: Ruby wrapper for SEOshop API - written by Yotpo
|
140
141
|
email:
|
141
142
|
- nimrod@yotpo.com
|
143
|
+
- vlad@yotpo.com
|
142
144
|
executables: []
|
143
145
|
extensions: []
|
144
146
|
extra_rdoc_files: []
|
145
147
|
files:
|
146
148
|
- ".gitignore"
|
149
|
+
- ".travis.yml"
|
147
150
|
- Gemfile
|
148
151
|
- Gemfile.lock
|
149
152
|
- LICENSE.txt
|
@@ -183,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
186
|
version: '0'
|
184
187
|
requirements: []
|
185
188
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.
|
189
|
+
rubygems_version: 2.6.8
|
187
190
|
signing_key:
|
188
191
|
specification_version: 4
|
189
192
|
summary: Ruby wrapper for SEOshop API - written by Yotpo
|