teespring 0.1.0 → 0.1.1

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: 47d395a0046f7c60bd1125d662f68565e716c9e1
4
- data.tar.gz: ce4287baf0a8c7c34336cceb17d8cffe5042bcca
3
+ metadata.gz: 7523636f6488a09cfee2991b1ae426977a310fc3
4
+ data.tar.gz: c640d1cbdce46177d65948868765a4e02d6745de
5
5
  SHA512:
6
- metadata.gz: 849cdf0be66efd108c651317ab8bf956c01fa2eb786b19add502f1a39560e35975ce9dae394ef4b9ed48b9742e99205752c396c14693427e08c899ff3f71b4ae
7
- data.tar.gz: fc22c441d513ae5dd9e2271b1a05c427de3a1e83d17454d8ee21a9001f2609d07bb64c22b5e6f6b96aa9f804ea5c74b6adb97067543c51b9a686985f83df5768
6
+ metadata.gz: 35cf607b92d2de3d792286b9a634fc27e174a830c1116850489f2cdf6632e34bb9779d8a57c64a5d5e7e420fc2139b7f6789a40dc1efb07ed1992c94379e9f79
7
+ data.tar.gz: 04e792e74e104fd3258074dadbb32baebea412e0494d1f4500a8ba0ccad557df8bc6749a9dcd7799b0a893f57c4de75b7b124c0a422a956a50f4dd3d2a16d7c1
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
data/README.md CHANGED
@@ -20,7 +20,42 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- In order to use this gem you must obtain an `app_id` from [Teespring](https://teespring.com/support).
23
+ In order to use this gem you must obtain an `app_id` from [Teespring](https://teespring.com/help).
24
+
25
+ Create a client:
26
+
27
+ ```ruby
28
+ client = Teespring::Client.new(app_id: "APP_ID_YOU_REQUESTED_FROM_TEESPRING")
29
+ ```
30
+
31
+ Authenticate (this will create a new access token):
32
+
33
+ ```ruby
34
+ token = client.authenticate("youremail@example.com", "yourpassword")
35
+ ```
36
+
37
+ Alternatively, if you already have an access token you can create the client with the token directly:
38
+
39
+ ```ruby
40
+ client = Teespring::Client.new(app_id: "APP_ID_YOU_REQUESTED_FROM_TEESPRING", access_token: "YOUR_ACCESS_TOKEN")
41
+ ```
42
+
43
+ Once the client is authenticated you can retrieve information about the authenticated (via the access token) user:
44
+
45
+ ```ruby
46
+ response = client.me
47
+ response.body
48
+ => {"users"=>[{"id"=>12345, "email"=>"youremail@example.com"}]}
49
+
50
+ ```
51
+
52
+ You can also retrieve a list of campaigns:
53
+
54
+ ```ruby
55
+ response = client.campaigns(nil, "active")
56
+ ```
57
+
58
+ Additional endpoints and details are available in the [Teespring Documentation](https://api.teespring.com/docs). Additional endpoints can be accessed directly through the `client.get` and `client.post` methods.
24
59
 
25
60
  ## Development
26
61
 
@@ -28,6 +63,13 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
28
63
 
29
64
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
65
 
66
+ ## TODO
67
+
68
+ * More Endpoints and response specific adapters
69
+ * Rate limiting
70
+ * Pagination
71
+ * Auto-pagination
72
+
31
73
  ## Contributing
32
74
 
33
75
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/teespring.
@@ -1,5 +1,7 @@
1
1
  require "teespring/version"
2
+ require "teespring/client"
3
+ require "teespring/response"
4
+ require "teespring/error"
2
5
 
3
6
  module Teespring
4
- # Your code goes here...
5
7
  end
@@ -0,0 +1,65 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Teespring
5
+ class Client
6
+ attr_accessor :access_token
7
+
8
+ def initialize(options = {})
9
+ @app_id = options.delete(:app_id)
10
+ end
11
+
12
+ def connection
13
+ @connection ||= ::Faraday.new(url: endpoint)
14
+ end
15
+
16
+ def reset
17
+ @connection = nil
18
+ end
19
+
20
+ def authenticate(email, password)
21
+ @response = post '/v1/auth-tokens', email: email, password: password, app_id: @app_id
22
+
23
+ @access_token = @response.body['token']
24
+ end
25
+
26
+ def me
27
+ @response = get '/me', { access_token: @access_token }
28
+ end
29
+
30
+ def campaigns(search = nil, states = nil)
31
+ @response = get '/seller/v1/campaigns', { access_token: @access_token, search: search, states: states, page: 1, per_page: 100 }
32
+ end
33
+
34
+ def get(url, params)
35
+ request(:get, url, params)
36
+ end
37
+
38
+ def post(url, params)
39
+ request(:post, url, params)
40
+ end
41
+
42
+ private
43
+
44
+ def request(method, url, params)
45
+ response = connection.send(method, url, params)
46
+
47
+ case response.status
48
+ when 200..299
49
+ Teespring::Response.new(response)
50
+ when 301
51
+ raise Teespring::Error.new('Not found', response)
52
+ when 400
53
+ message = JSON.parse(response.body)['error']['message'] rescue response.reason_phrase
54
+
55
+ raise Teespring::Error.new(message, response)
56
+ else
57
+ raise Teespring::Error.new('Unknown error', response)
58
+ end
59
+ end
60
+
61
+ def endpoint
62
+ "https://api.teespring.com"
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,11 @@
1
+ module Teespring
2
+ class Error < StandardError
3
+ attr_reader :response
4
+
5
+ def initialize(message, response)
6
+ @response = response
7
+
8
+ super(message)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'json'
2
+
3
+ module Teespring
4
+ class Response
5
+ attr_reader :response
6
+
7
+ def initialize(response)
8
+ @response = response
9
+ end
10
+
11
+ def body
12
+ @body ||= JSON.parse(response.body)
13
+ end
14
+
15
+ def status
16
+ response.status
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Teespring
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.12"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
+
26
+ spec.add_dependency "faraday", "~> 0.10"
25
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teespring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeffrafter
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
55
69
  description: Teespring provides a number of public and private APIs for creating,
56
70
  managing, and purchasing tee-shirts through their platform.
57
71
  email:
@@ -70,6 +84,9 @@ files:
70
84
  - bin/console
71
85
  - bin/setup
72
86
  - lib/teespring.rb
87
+ - lib/teespring/client.rb
88
+ - lib/teespring/error.rb
89
+ - lib/teespring/response.rb
73
90
  - lib/teespring/version.rb
74
91
  - teespring.gemspec
75
92
  homepage: https://github.com/jeffrafter/teespring