envato-sdk 0.0.1 → 0.0.2

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: 77469e8b80cdd6940d1b7f0e523d1b9617044c78
4
- data.tar.gz: d2e0007d126080cd368df50482d473f479673a5b
3
+ metadata.gz: 7b25ea02aebf38002ab812b9ee505998e0636721
4
+ data.tar.gz: 5d0e9b5e3df4e032b0f259cfbbf706f5c9c2c91d
5
5
  SHA512:
6
- metadata.gz: 1b6f64a85d45505bd672d5c2fed943061b71523be5a471ba51f590de2da85c71fbc7e7bb7f909e25f961cf96e16f2100becb968155e529dd73459255e71e4884
7
- data.tar.gz: 6d8ce3d3cd7466d1ef9b94ef6b640dec146523888ea1b7598c1d983ae605c4288d58fed75984b3bfee57b254e4861ee068f78858e233f49a879404ca976fba80
6
+ metadata.gz: 65230f1d52bed9ed809261c48055e6250d3a398cb9024ee28c9ee6b7b224b432112505ddaecd81f2b3a2cbba2355bd44647c08f38aee65fcb03c51c29dcfb5d4
7
+ data.tar.gz: 19a7eb12c52c740b2bbdc1830605eb06582252a9940b9491e3e3c7cf588459b30b55c8b2b208396d8e4e6279cfa5e1c0bf83c90b6dde602a5dbc71b286fdaec6
data/README.md CHANGED
@@ -76,7 +76,7 @@ $ rm -rf spec/cassettes/*
76
76
  # Pass your REAL credentials in as environment variables and run the RSpec
77
77
  # command.
78
78
  $ ENVATO_TEST_API_TOKEN=thisisarealtoken \
79
- ENVATO_TEST_API_TOKEN=thisisarealuser \
79
+ ENVATO_TEST_API_USERNAME=thisisarealuser \
80
80
  bundle exec rspec spec
81
81
  ```
82
82
 
@@ -0,0 +1,11 @@
1
+ module Envato
2
+ class Client
3
+ module Stats
4
+ def total_users
5
+ response = get 'market/total-users.json'
6
+ puts response.inspect
7
+ response['total-users']['total_users']
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/envato/client.rb CHANGED
@@ -1,30 +1,34 @@
1
- require 'faraday'
2
- require 'json'
1
+ require 'envato/connection'
2
+ require 'envato/configurable'
3
+ require 'envato/client/stats'
3
4
 
4
5
  module Envato
5
6
  class Client
7
+
8
+ include Envato::Connection
9
+ include Envato::Configurable
10
+ include Envato::Client::Stats
11
+
6
12
  def initialize(options = {})
7
- if options[:token].nil?
8
- raise MissingAPITokenError, 'You must define an API token for authorization.'
13
+ Envato::Configurable.keys.each do |key|
14
+ instance_variable_set(:"@#{key}", options[key] || Envato.instance_variable_get(:"@#{key}"))
9
15
  end
10
16
 
11
- @options = options
17
+ if @access_token.nil?
18
+ raise MissingAPITokenError, 'You must define an API token for authorization.'
19
+ end
12
20
  end
13
21
 
14
22
  def inspect
15
23
  inspected = super
16
24
 
17
- if @options[:token]
18
- inspected = inspected.gsub! @options[:token], conceal(@options[:token])
25
+ if @access_token
26
+ inspected = inspected.gsub! @access_token, conceal(@access_token)
19
27
  end
20
28
 
21
29
  inspected
22
30
  end
23
31
 
24
- def get(url)
25
- request :get, url
26
- end
27
-
28
32
  def conceal(string)
29
33
  if string.length < 8
30
34
  '****'
@@ -34,47 +38,5 @@ module Envato
34
38
  "#{front}****#{back}"
35
39
  end
36
40
  end
37
-
38
- def proxy?
39
- (ENV['HTTPS_PROXY'].nil? || ENV['HTTPS_PROXY'].empty?) ? false : true
40
- end
41
-
42
- def proxy_opts
43
- (proxy?) ? { uri: ENV['HTTPS_PROXY'] } : nil
44
- end
45
-
46
- def ssl_opts
47
- { verify: true }
48
- end
49
-
50
- def api_host
51
- 'https://api.envato.com'
52
- end
53
-
54
- def api_version
55
- 'v1'
56
- end
57
-
58
- private
59
-
60
- def request(method, url, options = {})
61
- request = Faraday.new(url: api_host, ssl: ssl_opts) do |c|
62
- c.adapter Faraday.default_adapter
63
- c.headers['User-Agent'] = "Envato SDK (#{Envato::VERSION})"
64
- c.authorization(:Bearer, @options[:token])
65
- c.proxy proxy_opts
66
- end
67
-
68
- case method
69
- when :get
70
- response = request.get "#{api_version}/#{url}"
71
- end
72
-
73
- begin
74
- JSON.parse(response.body)
75
- rescue JSON::ParserError
76
- response.body
77
- end
78
- end
79
41
  end
80
42
  end
@@ -0,0 +1,25 @@
1
+ module Envato
2
+ module Configurable
3
+ attr_accessor :access_token, :proxy, :username
4
+
5
+ class << self
6
+ def keys
7
+ @keys ||= [
8
+ :username,
9
+ :access_token,
10
+ :proxy
11
+ ]
12
+ end
13
+ end
14
+
15
+ def configure
16
+ yield self
17
+ end
18
+
19
+ private
20
+
21
+ def options
22
+ Hash[Envato::Configurable.keys.map{ |key| [key, instance_variable_get(:"@#{key}")] }]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Envato
5
+ module Connection
6
+ def get(url)
7
+ request :get, url
8
+ end
9
+
10
+ def ssl_opts
11
+ { verify: true }
12
+ end
13
+
14
+ def api_host
15
+ 'https://api.envato.com'
16
+ end
17
+
18
+ def api_version
19
+ 'v1'
20
+ end
21
+
22
+ private
23
+
24
+ def request(method, url, options = {})
25
+ request = Faraday.new(url: api_host, ssl: ssl_opts) do |c|
26
+ c.adapter Faraday.default_adapter
27
+ c.headers['User-Agent'] = "Envato SDK (#{Envato::VERSION})"
28
+ c.authorization(:Bearer, @access_token)
29
+ c.proxy(@proxy) if @proxy
30
+ end
31
+
32
+ case method
33
+ when :get
34
+ response = request.get "#{api_version}/#{url}"
35
+ end
36
+
37
+ begin
38
+ JSON.parse(response.body)
39
+ rescue JSON::ParserError
40
+ response.body
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,6 +1,6 @@
1
1
  module Envato
2
2
  MAJOR = 0
3
3
  MINOR = 0
4
- PATCH = 1
4
+ PATCH = 2
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.1
4
+ version: 0.0.2
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-15 00:00:00.000000000 Z
11
+ date: 2015-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -144,6 +144,9 @@ files:
144
144
  - lib/envato-sdk.rb
145
145
  - lib/envato.rb
146
146
  - lib/envato/client.rb
147
+ - lib/envato/client/stats.rb
148
+ - lib/envato/configurable.rb
149
+ - lib/envato/connection.rb
147
150
  - lib/envato/errors.rb
148
151
  - lib/envato/version.rb
149
152
  homepage: https://build.envato.com