envato-sdk 0.0.2 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b25ea02aebf38002ab812b9ee505998e0636721
4
- data.tar.gz: 5d0e9b5e3df4e032b0f259cfbbf706f5c9c2c91d
3
+ metadata.gz: f1bacaabd361c44b274e342c5e3e9d43faebce08
4
+ data.tar.gz: 6d72f24746da821ef6d09dca4575a1084a86b1e4
5
5
  SHA512:
6
- metadata.gz: 65230f1d52bed9ed809261c48055e6250d3a398cb9024ee28c9ee6b7b224b432112505ddaecd81f2b3a2cbba2355bd44647c08f38aee65fcb03c51c29dcfb5d4
7
- data.tar.gz: 19a7eb12c52c740b2bbdc1830605eb06582252a9940b9491e3e3c7cf588459b30b55c8b2b208396d8e4e6279cfa5e1c0bf83c90b6dde602a5dbc71b286fdaec6
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(token: 'mytops3crettoken')
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(token: 'mytops3crettoken')
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
 
@@ -3,7 +3,6 @@ module Envato
3
3
  module Stats
4
4
  def total_users
5
5
  response = get 'market/total-users.json'
6
- puts response.inspect
7
6
  response['total-users']['total_users']
8
7
  end
9
8
  end
@@ -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
- # User is missing the required API token.
2
- class MissingAPITokenError < ArgumentError; end
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
@@ -1,6 +1,6 @@
1
1
  module Envato
2
2
  MAJOR = 0
3
3
  MINOR = 0
4
- PATCH = 2
4
+ PATCH = 4
5
5
  VERSION = [MAJOR, MINOR, PATCH].join '.'
6
6
  end
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.2
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-10-17 00:00:00.000000000 Z
11
+ date: 2015-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler