envato-sdk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 77469e8b80cdd6940d1b7f0e523d1b9617044c78
4
+ data.tar.gz: d2e0007d126080cd368df50482d473f479673a5b
5
+ SHA512:
6
+ metadata.gz: 1b6f64a85d45505bd672d5c2fed943061b71523be5a471ba51f590de2da85c71fbc7e7bb7f909e25f961cf96e16f2100becb968155e529dd73459255e71e4884
7
+ data.tar.gz: 6d8ce3d3cd7466d1ef9b94ef6b640dec146523888ea1b7598c1d983ae605c4288d58fed75984b3bfee57b254e4861ee068f78858e233f49a879404ca976fba80
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jacob Bednarz
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,112 @@
1
+ # Envato Ruby SDK [![Build Status](https://travis-ci.org/jacobbednarz/envato-ruby-sdk.svg?branch=master)](https://travis-ci.org/jacobbednarz/envato-ruby-sdk)
2
+
3
+ Interact with the [Envato API][envato_api_url] using Ruby.
4
+
5
+ ## Installation
6
+
7
+ Quickstart
8
+
9
+ ```
10
+ $ gem install envato-sdk
11
+ ```
12
+
13
+ Or using a Gemfile:
14
+
15
+ ```
16
+ $ gem 'envato-sdk'
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ First things first. Create an instance of the client which will be used by all
22
+ connections from here on out.
23
+
24
+ ```rb
25
+ client = Envato::Client.new(token: 'mytops3crettoken')
26
+
27
+ # Send a 'GET' for the total number of users.
28
+ response = client.get 'market/total-users.json'
29
+ # => {"total-users"=>{"total_users"=>"5942654"}}
30
+ ```
31
+
32
+ As this project grows the endpoints will be wrapped in usable methods so instead
33
+ of building the request above, you can use the following:
34
+
35
+ ```rb
36
+ client = Envato::Client.new(token: 'mytops3crettoken')
37
+ client.total_users
38
+ # => 8676143
39
+
40
+ # Or maybe...
41
+ user_count = Envato::Users.total
42
+ ```
43
+
44
+ ## Testing
45
+
46
+ RSpec is the testing tool of choice and you can kick off the test suite by
47
+ running:
48
+
49
+ ```
50
+ $ bundle exec rspec spec
51
+ ```
52
+
53
+ The following Ruby versions are supported (and [tested against][travis_ci_url]):
54
+
55
+ - Ruby 2.0
56
+ - Ruby 2.1
57
+ - Ruby 2.2
58
+
59
+ ## Using VCR
60
+
61
+ To ensure the test suite runs nice and fast we use VCR which generates our mocks
62
+ but using a real request that is stored inside of `spec/cassettes`. The way it
63
+ achieves this is it that each HTTP request is wrapped in a block which captures
64
+ the request, filters sensitive data and then stores it for the next person to
65
+ use. This means that not everyone needs to generate fresh requests and can
66
+ leverage known working responses.
67
+
68
+ As with all mocks, when the endpoint or functionality changes it is a good idea
69
+ to re-do them to ensure you are still testing against live endpoints. To do that
70
+ in this project, you'll need to run the following:
71
+
72
+ ```
73
+ # Remove the existing files. You can be more specific here if you need to be.
74
+ $ rm -rf spec/cassettes/*
75
+
76
+ # Pass your REAL credentials in as environment variables and run the RSpec
77
+ # command.
78
+ $ ENVATO_TEST_API_TOKEN=thisisarealtoken \
79
+ ENVATO_TEST_API_TOKEN=thisisarealuser \
80
+ bundle exec rspec spec
81
+ ```
82
+
83
+ It's super important you use real credentials when re-generating the cassettes
84
+ to ensure it is an accurate representation of the interactions. (Don't worry, we
85
+ don't commit your details to the cassettes they are filtered out by VCR!)
86
+
87
+ ## Releasing a new version
88
+
89
+ Everything you need to build a new release can be done by running:
90
+
91
+ ```
92
+ $ script/release
93
+ ```
94
+
95
+ This will handle pushing a new version of the gem to rubygems.org, a tag to
96
+ GitHub and updating the `master` branch.
97
+
98
+ ## Contributing
99
+
100
+ Contributions are welcome (in fact, encouraged!) to this project. To ensure
101
+ everything continues humming along nicely, there are a few guidelines.
102
+
103
+ - All code changes **must** add tests for the functionality. Without tests
104
+ someone may accidently break your changes and cause regressions.
105
+ - If looking to add a large piece of new functionality,
106
+ [open an issue][new_issue_url] first and get some feedback on whether it's
107
+ something the maintainers are willing to accept. We don't want anyone wasting
108
+ time on changes only to be told the project won't accept them.
109
+
110
+ [envato_api_url]: https://build.envato.com
111
+ [travis_ci_url]: https://travis-ci.org/jacobbednarz/envato-ruby-sdk
112
+ [new_issue_url]: https://github.com/jacobbednarz/envato-ruby-sdk/issues/new
data/lib/envato-sdk.rb ADDED
@@ -0,0 +1,2 @@
1
+ # This is here so that we can have a different gem name to the class names.
2
+ require 'envato'
data/lib/envato.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'envato/client'
2
+ require 'envato/errors'
3
+ require 'envato/version'
@@ -0,0 +1,80 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Envato
5
+ class Client
6
+ def initialize(options = {})
7
+ if options[:token].nil?
8
+ raise MissingAPITokenError, 'You must define an API token for authorization.'
9
+ end
10
+
11
+ @options = options
12
+ end
13
+
14
+ def inspect
15
+ inspected = super
16
+
17
+ if @options[:token]
18
+ inspected = inspected.gsub! @options[:token], conceal(@options[:token])
19
+ end
20
+
21
+ inspected
22
+ end
23
+
24
+ def get(url)
25
+ request :get, url
26
+ end
27
+
28
+ def conceal(string)
29
+ if string.length < 8
30
+ '****'
31
+ else
32
+ front = string[0, 4]
33
+ back = string[-4, 4]
34
+ "#{front}****#{back}"
35
+ end
36
+ 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
+ end
80
+ end
@@ -0,0 +1,2 @@
1
+ # User is missing the required API token.
2
+ class MissingAPITokenError < ArgumentError; end
@@ -0,0 +1,6 @@
1
+ module Envato
2
+ MAJOR = 0
3
+ MINOR = 0
4
+ PATCH = 1
5
+ VERSION = [MAJOR, MINOR, PATCH].join '.'
6
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: envato-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jacob Bednarz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.0.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.0.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: vcr
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.7'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 2.7.0
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '2.7'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.7.0
81
+ - !ruby/object:Gem::Dependency
82
+ name: webmock
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '1.15'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '1.15'
95
+ - !ruby/object:Gem::Dependency
96
+ name: faraday
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '0.8'
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 0.8.9
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '0.8'
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 0.8.9
115
+ - !ruby/object:Gem::Dependency
116
+ name: multi_json
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '1.8'
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 1.8.2
125
+ type: :runtime
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.8'
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 1.8.2
135
+ description: SDK for interacting with the Envato API.
136
+ email:
137
+ - jacob.bednarz@envato.com
138
+ executables: []
139
+ extensions: []
140
+ extra_rdoc_files: []
141
+ files:
142
+ - LICENSE
143
+ - README.md
144
+ - lib/envato-sdk.rb
145
+ - lib/envato.rb
146
+ - lib/envato/client.rb
147
+ - lib/envato/errors.rb
148
+ - lib/envato/version.rb
149
+ homepage: https://build.envato.com
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: '2.0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.2.5
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: SDK for interacting with the Envato API.
173
+ test_files: []