envato-sdk 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/envato/client.rb +1 -3
- data/lib/envato/client/stats.rb +0 -1
- data/lib/envato/connection.rb +12 -0
- data/lib/envato/errors.rb +12 -2
- data/lib/envato/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1bacaabd361c44b274e342c5e3e9d43faebce08
|
4
|
+
data.tar.gz: 6d72f24746da821ef6d09dca4575a1084a86b1e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2e168def139ca0f70dc2721ad8de842df5a302187490d6711793c6772d2d5ffabb58404032752074470e3b5fa40ab893f655b1b225de3d2b5f91a5d5dbf2810
|
7
|
+
data.tar.gz: 40184663b24fe489d459139e8422585441bc9b4bfe94f66b6f1d095f8b8b4280b6e713c37c80654391020c69b6665a17bb41414ebc5c216456ae9beac9e8f05d
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ First things first. Create an instance of the client which will be used by all
|
|
22
22
|
connections from here on out.
|
23
23
|
|
24
24
|
```rb
|
25
|
-
client = Envato::Client.new(
|
25
|
+
client = Envato::Client.new(access_token: 'mytops3crettoken')
|
26
26
|
|
27
27
|
# Send a 'GET' for the total number of users.
|
28
28
|
response = client.get 'market/total-users.json'
|
@@ -33,7 +33,7 @@ As this project grows the endpoints will be wrapped in usable methods so instead
|
|
33
33
|
of building the request above, you can use the following:
|
34
34
|
|
35
35
|
```rb
|
36
|
-
client = Envato::Client.new(
|
36
|
+
client = Envato::Client.new(access_token: 'mytops3crettoken')
|
37
37
|
client.total_users
|
38
38
|
# => 8676143
|
39
39
|
|
data/lib/envato/client.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'envato/connection'
|
2
2
|
require 'envato/configurable'
|
3
|
-
require 'envato/client/stats'
|
4
3
|
|
5
4
|
module Envato
|
6
5
|
class Client
|
7
6
|
|
8
7
|
include Envato::Connection
|
9
8
|
include Envato::Configurable
|
10
|
-
include Envato::Client::Stats
|
11
9
|
|
12
10
|
def initialize(options = {})
|
13
11
|
Envato::Configurable.keys.each do |key|
|
@@ -15,7 +13,7 @@ module Envato
|
|
15
13
|
end
|
16
14
|
|
17
15
|
if @access_token.nil?
|
18
|
-
raise MissingAPITokenError, 'You must define an API token for authorization.'
|
16
|
+
raise Envato::MissingAPITokenError, 'You must define an API access token for authorization.'
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
data/lib/envato/client/stats.rb
CHANGED
data/lib/envato/connection.rb
CHANGED
@@ -34,11 +34,23 @@ module Envato
|
|
34
34
|
response = request.get "#{api_version}/#{url}"
|
35
35
|
end
|
36
36
|
|
37
|
+
case response.status.to_i
|
38
|
+
when 403 then raise Envato::ForbiddenError, extract_forbidden_message(response)
|
39
|
+
when 404 then raise Envato::NotFoundError
|
40
|
+
when 405..499 then raise Envato::ClientError
|
41
|
+
when 500..599 then raise Envato::ServerError
|
42
|
+
end
|
43
|
+
|
37
44
|
begin
|
38
45
|
JSON.parse(response.body)
|
39
46
|
rescue JSON::ParserError
|
40
47
|
response.body
|
41
48
|
end
|
42
49
|
end
|
50
|
+
|
51
|
+
def extract_forbidden_message(response)
|
52
|
+
body = JSON.parse(response.body)
|
53
|
+
body['error_description']
|
54
|
+
end
|
43
55
|
end
|
44
56
|
end
|
data/lib/envato/errors.rb
CHANGED
@@ -1,2 +1,12 @@
|
|
1
|
-
|
2
|
-
class
|
1
|
+
module Envato
|
2
|
+
class Error < StandardError; end
|
3
|
+
|
4
|
+
# User is missing the required API token.
|
5
|
+
class MissingAPITokenError < ArgumentError; end
|
6
|
+
|
7
|
+
# Handle the HTTP statuses correctly.
|
8
|
+
class ForbiddenError < Error; end
|
9
|
+
class NotFoundError < Error; end
|
10
|
+
class ClientError < Error; end
|
11
|
+
class ServerError < Error; end
|
12
|
+
end
|
data/lib/envato/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envato-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Bednarz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|