reshape 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +77 -0
- data/Rakefile +8 -0
- data/examples/Gemfile +6 -0
- data/examples/config.ru +45 -0
- data/lib/faraday/response/raise_reshape_api_error.rb +41 -0
- data/lib/reshape/client/categories.rb +15 -0
- data/lib/reshape/client/materials.rb +15 -0
- data/lib/reshape/client/models.rb +43 -0
- data/lib/reshape/client/orders.rb +21 -0
- data/lib/reshape/client/price.rb +22 -0
- data/lib/reshape/client/printers.rb +15 -0
- data/lib/reshape/client.rb +34 -0
- data/lib/reshape/configuration.rb +63 -0
- data/lib/reshape/connection.rb +38 -0
- data/lib/reshape/error.rb +31 -0
- data/lib/reshape/request.rb +42 -0
- data/lib/reshape/version.rb +3 -0
- data/lib/reshape.rb +20 -0
- data/reshape.gemspec +33 -0
- data/spec/faraday/response_spec.rb +40 -0
- data/spec/fixtures/cassettes/add_to_cart.yml +65 -0
- data/spec/fixtures/cassettes/cart.yml +64 -0
- data/spec/fixtures/cassettes/categories.yml +71 -0
- data/spec/fixtures/cassettes/category.yml +64 -0
- data/spec/fixtures/cassettes/material.yml +65 -0
- data/spec/fixtures/cassettes/materials.yml +91 -0
- data/spec/fixtures/cassettes/model.yml +65 -0
- data/spec/fixtures/cassettes/model_file_by_version.yml +64 -0
- data/spec/fixtures/cassettes/model_info.yml +65 -0
- data/spec/fixtures/cassettes/models.yml +64 -0
- data/spec/fixtures/cassettes/price.yml +65 -0
- data/spec/fixtures/cassettes/printer.yml +64 -0
- data/spec/fixtures/cassettes/printers.yml +85 -0
- data/spec/fixtures/cassettes/update_model_info.yml +67 -0
- data/spec/reshape/client/categories_spec.rb +29 -0
- data/spec/reshape/client/materials_spec.rb +28 -0
- data/spec/reshape/client/models_spec.rb +73 -0
- data/spec/reshape/client/orders_spec.rb +28 -0
- data/spec/reshape/client/price_spec.rb +20 -0
- data/spec/reshape/client/printers_spec.rb +30 -0
- data/spec/reshape/client_spec.rb +49 -0
- data/spec/reshape_spec.rb +21 -0
- data/spec/spec_helper.rb +72 -0
- metadata +268 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 97ce0c036d8b1e1ee167623535faab9d3edec236
|
4
|
+
data.tar.gz: 821216ca55ba7fb15f8902a934b572ce88594a8c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1fa673a17b7d6f7bf484a9669226c5c22a542b8a328def3169a66fe707d26cce2d5d8e2f795d4d77d32c8780bcfa72525a3463303e2dfd0cb20b6bcf777ead6
|
7
|
+
data.tar.gz: 3ffd941a5c3ba8c568f0d06ccfe6fac9a487ae0ad6a1d3b4870e2ea06090675e212121d6436ddece75a6e7b63740fa97929d1c074319fc446d226e5864afae19
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 John Barton
|
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,77 @@
|
|
1
|
+
# Reshape: An API Wrapper for Shapeways
|
2
|
+
|
3
|
+
This gem is an API wrapper for the [Shapeways API](http://developer.shapeways.com/)
|
4
|
+
|
5
|
+
It supports the Shapeways API which uses OAuth 1.0a.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
This gem does not contain any methods for authentication. Everyone tends to use something a little bit different, so the goal was to abstract out the OAuth authentication and allow you to bring your own, if you desire. You only need to supply the tokens. However, I also created an OmniAuth strategy to support the Shapeways API. So, if you're already using OmniAuth in your project, you can easily add the strategy with my omniauth-shapewats gem according to the instructions found here: [Shapeways OmniAuth Strategy](/phy5ics/omniauth-shapeways)
|
10
|
+
|
11
|
+
Add the gem to your `Gemfile`:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'reshape'
|
15
|
+
```
|
16
|
+
|
17
|
+
Then instantiate the client using the oAuth tokens (this example implies using Foreman and an .env file that contain these values):
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
Reshape::Client.new({
|
21
|
+
consumer_token: ENV['SHAPEWAYS_CONSUMER_TOKEN'],
|
22
|
+
consumer_secret: ENV['SHAPEWAYS_CONSUMER_SECRET'],
|
23
|
+
oauth_token: ENV['SHAPEWAYS_OAUTH_TOKEN'],
|
24
|
+
oauth_secret: ENV['SHAPEWAYS_OAUTH_SECRET']
|
25
|
+
})
|
26
|
+
```
|
27
|
+
|
28
|
+
The consumer_token and consumer_secret are supplied by Shapeways once you create a developer account and an app. Additional information can be found on the [Shapeways Developer Site](http://developer.shapeways.com/).
|
29
|
+
|
30
|
+
The oauth_token and oauth_secret are the access tokens that are received from the OAuth transaction. In this Sinatra method that uses the OmniAuth callback method, you can see how to parse the access tokens out of the response and use it to instantiate the Reshape client along with your pre-defined consumer tokens:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
get '/auth/:provider/callback' do
|
34
|
+
auth = request.env['omniauth.auth']
|
35
|
+
|
36
|
+
client = Reshape::Client.new({
|
37
|
+
consumer_token: ENV['SHAPEWAYS_CONSUMER_TOKEN'],
|
38
|
+
consumer_secret: ENV['SHAPEWAYS_CONSUMER_SECRET'],
|
39
|
+
oauth_token: auth.credentials.token,
|
40
|
+
oauth_secret: auth.credentials.secret
|
41
|
+
})
|
42
|
+
|
43
|
+
erb "<pre>#{JSON.pretty_generate(client.materials)}</pre>"
|
44
|
+
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Check the examples directory for a full example using Sinatra.
|
49
|
+
|
50
|
+
## Todo
|
51
|
+
|
52
|
+
Add rspec tests for adding models and photos.
|
53
|
+
|
54
|
+
|
55
|
+
## <a name="build"></a>Build Status
|
56
|
+
[![Build Status](https://secure.travis-ci.org/phy5ics/reshape.png?branch=master)][travis]
|
57
|
+
|
58
|
+
[travis]: http://travis-ci.org/phy5ics/omniauth-shapeways
|
59
|
+
|
60
|
+
## <a name="dependencies"></a>Dependency Status
|
61
|
+
[![Dependency Status](https://gemnasium.com/phy5ics/reshape.png?travis)][gemnasium]
|
62
|
+
|
63
|
+
[gemnasium]: https://gemnasium.com/phy5ics/reshape
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
* Fork the project.
|
68
|
+
* Make your feature addition or bug fix.
|
69
|
+
* Add tests for it. This is important so I don't break it in a
|
70
|
+
future version unintentionally.
|
71
|
+
* Commit, do not mess with rakefile, version, or history.
|
72
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
73
|
+
* Send me a pull request. Bonus points for topic branches.
|
74
|
+
|
75
|
+
## Copyright
|
76
|
+
|
77
|
+
Copyright (c) 2013 John Barton. See [LICENSE](https://github.com/phy5ics/reshape/blob/master/LICENSE.txt) for details.
|
data/Rakefile
ADDED
data/examples/Gemfile
ADDED
data/examples/config.ru
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'omniauth-shapeways'
|
4
|
+
require 'reshape'
|
5
|
+
|
6
|
+
# Get these keys from http://developer.shapeways.com
|
7
|
+
ENV['CONSUMER_KEY'] = '61b13483fc0caf31f986026ce2add918d3fa9377'
|
8
|
+
ENV['CONSUMER_SECRET'] = 'd0482b1653e67cfd25057c257eedd48a5cb8b66e'
|
9
|
+
|
10
|
+
# To run this example:
|
11
|
+
# $ bundle install
|
12
|
+
# $ rackup -p 9293 config.ru &
|
13
|
+
|
14
|
+
class App < Sinatra::Base
|
15
|
+
get '/' do
|
16
|
+
redirect '/auth/shapeways'
|
17
|
+
end
|
18
|
+
|
19
|
+
get '/auth/:provider/callback' do
|
20
|
+
auth = request.env['omniauth.auth']
|
21
|
+
client = Reshape::Client.new({
|
22
|
+
consumer_token: ENV['SHAPEWAYS_CONSUMER_TOKEN'],
|
23
|
+
consumer_secret: ENV['SHAPEWAYS_CONSUMER_SECRET'],
|
24
|
+
oauth_token: auth.credentials.token,
|
25
|
+
oauth_secret: auth.credentials.secret
|
26
|
+
})
|
27
|
+
materials = client.materials
|
28
|
+
|
29
|
+
erb "<h1>#{params[:provider]}</h1>
|
30
|
+
<pre>#{JSON.pretty_generate(auth)}</pre>
|
31
|
+
<pre>#{JSON.pretty_generate(materials)}</pre>"
|
32
|
+
end
|
33
|
+
|
34
|
+
get '/auth/failure' do
|
35
|
+
MultiJson.encode(request.env)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
use Rack::Session::Cookie
|
40
|
+
|
41
|
+
use OmniAuth::Builder do
|
42
|
+
provider :shapeways, ENV['CONSUMER_KEY'], ENV['CONSUMER_SECRET']
|
43
|
+
end
|
44
|
+
|
45
|
+
run App.new
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module Faraday
|
5
|
+
class Response::RaiseReshapeApiError < Response::Middleware
|
6
|
+
def on_complete(response)
|
7
|
+
case response[:status].to_i
|
8
|
+
when 400
|
9
|
+
raise Reshape::BadRequest, error_message(response)
|
10
|
+
when 401
|
11
|
+
raise Reshape::Unauthorized, error_message(response)
|
12
|
+
when 403
|
13
|
+
raise Reshape::Forbidden, error_message(response)
|
14
|
+
when 404
|
15
|
+
raise Reshape::NotFound, error_message(response)
|
16
|
+
when 406
|
17
|
+
raise Reshape::NotAcceptable, error_message(response)
|
18
|
+
when 422
|
19
|
+
raise Reshape::UnprocessableEntity, error_message(response)
|
20
|
+
when 500
|
21
|
+
raise Reshape::InternalServerError, error_message(response)
|
22
|
+
when 502
|
23
|
+
raise Reshape::BadGateway, error_message(response)
|
24
|
+
when 503
|
25
|
+
raise Reshape::ServiceUnavailable, error_message(response)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def error_message(response)
|
30
|
+
message = if (body = response[:body]) && !body.empty?
|
31
|
+
if body.is_a?(String)
|
32
|
+
body = MultiJson.load(body, :symbolize_keys => true)
|
33
|
+
end
|
34
|
+
": #{body[:error] || body[:message] || ''}"
|
35
|
+
else
|
36
|
+
''
|
37
|
+
end
|
38
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{message}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Reshape
|
2
|
+
class Client
|
3
|
+
module Categories
|
4
|
+
|
5
|
+
def categories(options={}, raw=false)
|
6
|
+
get("/categories/#{api_version}", options, raw)
|
7
|
+
end
|
8
|
+
|
9
|
+
def category(id, options={}, raw=false)
|
10
|
+
get("/categories/#{id}/#{api_version}", options, raw)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Reshape
|
2
|
+
class Client
|
3
|
+
module Materials
|
4
|
+
|
5
|
+
def materials(options={}, raw=false)
|
6
|
+
get("/materials/#{api_version}", options, raw)
|
7
|
+
end
|
8
|
+
|
9
|
+
def material(id, options={}, raw=false)
|
10
|
+
get("/materials/#{id}/#{api_version}", options, raw)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Reshape
|
2
|
+
class Client
|
3
|
+
module Models
|
4
|
+
|
5
|
+
def models(options={}, raw=false)
|
6
|
+
get("/models/#{api_version}", options, raw)
|
7
|
+
end
|
8
|
+
|
9
|
+
def model(id, options={}, raw=false)
|
10
|
+
get("/models/#{id}/#{api_version}", options, raw)
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_model(file, name, rights, terms, options={}, raw=false)
|
14
|
+
post("/models/#{api_version}", options.merge(file: file, fileName: name, hasRightsToModel: rights, acceptTermsAndConditions: terms), raw)
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete_model(id, options={}, raw=false)
|
18
|
+
delete("/model/#{id}/#{api_version}", options, raw)
|
19
|
+
end
|
20
|
+
|
21
|
+
def model_info(id, options={}, raw=false)
|
22
|
+
get("/models/#{id}/info/#{api_version}", options, raw)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_model_info(id, options={}, raw=false)
|
26
|
+
put("/models/#{id}/info/#{api_version}", options, raw)
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_model_file(id, file, name, rights, terms, options={}, raw=false)
|
30
|
+
post("/models/#{id}/files/#{api_version}", options.merge(file: file, fileName: name, hasRightsToModel: rights, acceptTermsAndConditions: terms), raw)
|
31
|
+
end
|
32
|
+
|
33
|
+
def model_file_by_version(id, fileVersion, options={}, raw=false)
|
34
|
+
get("/models/#{id}/files/#{fileVersion}/v1")
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_model_photo(id, file, options={}, raw=false)
|
38
|
+
post("/models/#{id}/photos/#{api_version}")
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Reshape
|
2
|
+
class Client
|
3
|
+
module Orders
|
4
|
+
|
5
|
+
def cart(options={}, raw=false)
|
6
|
+
get("/orders/cart/#{api_version}", options, raw)
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_to_cart(model_id, material_id, quantity, options={}, raw=false)
|
10
|
+
options.merge!(
|
11
|
+
{
|
12
|
+
modelId: model_id,
|
13
|
+
materialId: material_id,
|
14
|
+
quantity: quantity
|
15
|
+
})
|
16
|
+
post("/orders/cart/#{api_version}", options, raw)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Reshape
|
2
|
+
class Client
|
3
|
+
module Price
|
4
|
+
|
5
|
+
def price(volume, area, x_bound_min, x_bound_max, y_bound_min, y_bound_max, z_bound_min, z_bound_max, options={}, raw=false)
|
6
|
+
options.merge!(
|
7
|
+
{
|
8
|
+
volume: volume,
|
9
|
+
area: area,
|
10
|
+
xBoundMin: x_bound_min,
|
11
|
+
xBoundMax: x_bound_max,
|
12
|
+
yBoundMin: y_bound_min,
|
13
|
+
yBoundMax: y_bound_max,
|
14
|
+
zBoundMin: z_bound_min,
|
15
|
+
zBoundMax: z_bound_max
|
16
|
+
})
|
17
|
+
post("/price/#{api_version}", options, raw)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Reshape
|
2
|
+
class Client
|
3
|
+
module Printers
|
4
|
+
|
5
|
+
def printers(options={}, raw=false)
|
6
|
+
get("/printers/#{api_version}", options, raw)
|
7
|
+
end
|
8
|
+
|
9
|
+
def printer(id, options={}, raw=false)
|
10
|
+
get("/printers/#{id}/#{api_version}", options, raw)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'reshape/configuration'
|
2
|
+
require 'reshape/connection'
|
3
|
+
require 'reshape/request'
|
4
|
+
require 'reshape/error'
|
5
|
+
require 'reshape/client/orders'
|
6
|
+
require 'reshape/client/materials'
|
7
|
+
require 'reshape/client/models'
|
8
|
+
require 'reshape/client/printers'
|
9
|
+
require 'reshape/client/price'
|
10
|
+
require 'reshape/client/categories'
|
11
|
+
|
12
|
+
module Reshape
|
13
|
+
class Client
|
14
|
+
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
15
|
+
|
16
|
+
def initialize(options={})
|
17
|
+
options = Reshape.options.merge(options)
|
18
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
19
|
+
send("#{key}=", options[key])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
include Reshape::Configuration
|
24
|
+
include Reshape::Connection
|
25
|
+
include Reshape::Request
|
26
|
+
include Reshape::Client::Orders
|
27
|
+
include Reshape::Client::Materials
|
28
|
+
include Reshape::Client::Models
|
29
|
+
include Reshape::Client::Printers
|
30
|
+
include Reshape::Client::Price
|
31
|
+
include Reshape::Client::Categories
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'reshape/version'
|
3
|
+
|
4
|
+
module Reshape
|
5
|
+
module Configuration
|
6
|
+
VALID_OPTIONS_KEYS = [
|
7
|
+
:adapter,
|
8
|
+
:api_version,
|
9
|
+
:api_endpoint,
|
10
|
+
:web_endpoint,
|
11
|
+
:proxy,
|
12
|
+
:consumer_token,
|
13
|
+
:consumer_secret,
|
14
|
+
:consumer_options,
|
15
|
+
:oauth_token,
|
16
|
+
:oauth_secret,
|
17
|
+
:response_format,
|
18
|
+
:user_agent].freeze
|
19
|
+
|
20
|
+
DEFAULT_ADAPTER = Faraday.default_adapter
|
21
|
+
DEFAULT_API_VERSION = 'v1'
|
22
|
+
DEFAULT_API_ENDPOINT = 'http://api.shapeways.com/'
|
23
|
+
DEFAULT_WEB_ENDPOINT = 'http://www.shapeways.com/'
|
24
|
+
DEFAULT_USER_AGENT = "Reshape Rubygem #{Reshape::VERSION}".freeze
|
25
|
+
DEFAULT_RESPONSE_FORMAT = 'json'
|
26
|
+
|
27
|
+
attr_accessor(*VALID_OPTIONS_KEYS)
|
28
|
+
|
29
|
+
def self.extended(base)
|
30
|
+
base.reset
|
31
|
+
end
|
32
|
+
|
33
|
+
def configure
|
34
|
+
yield self
|
35
|
+
end
|
36
|
+
|
37
|
+
def options
|
38
|
+
VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def api_endpoint=(value)
|
42
|
+
@api_endpoint = File.join(value, "")
|
43
|
+
end
|
44
|
+
|
45
|
+
def web_endpoint=(value)
|
46
|
+
@web_endpoint = File.join(value, "")
|
47
|
+
end
|
48
|
+
|
49
|
+
def reset
|
50
|
+
self.adapter = DEFAULT_ADAPTER
|
51
|
+
self.api_version = DEFAULT_API_VERSION
|
52
|
+
self.api_endpoint = DEFAULT_API_ENDPOINT
|
53
|
+
self.web_endpoint = DEFAULT_WEB_ENDPOINT
|
54
|
+
self.proxy = nil
|
55
|
+
self.consumer_token = nil
|
56
|
+
self.consumer_secret = nil
|
57
|
+
self.oauth_token = nil
|
58
|
+
self.oauth_secret = nil
|
59
|
+
self.response_format = DEFAULT_RESPONSE_FORMAT
|
60
|
+
self.user_agent = DEFAULT_USER_AGENT
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require 'faraday/response/raise_reshape_api_error'
|
3
|
+
|
4
|
+
module Reshape
|
5
|
+
module Connection
|
6
|
+
private
|
7
|
+
def oauth_data
|
8
|
+
{
|
9
|
+
consumer_key: @consumer_token,
|
10
|
+
consumer_secret: @consumer_secret,
|
11
|
+
token: @oauth_token,
|
12
|
+
token_secret: @oauth_secret
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def connection(raw=false, force_urlencoded=false)
|
17
|
+
url = "#{Reshape.api_endpoint}"
|
18
|
+
|
19
|
+
options = {
|
20
|
+
url: url,
|
21
|
+
proxy: proxy,
|
22
|
+
ssl: { verify: false },
|
23
|
+
}
|
24
|
+
|
25
|
+
connection = Faraday.new(options) do |builder|
|
26
|
+
builder.use Faraday::Response::RaiseReshapeApiError
|
27
|
+
builder.request :json
|
28
|
+
builder.request :oauth, oauth_data
|
29
|
+
unless raw
|
30
|
+
builder.use FaradayMiddleware::Mashify
|
31
|
+
builder.use FaradayMiddleware::ParseJson
|
32
|
+
end
|
33
|
+
builder.adapter *adapter
|
34
|
+
end
|
35
|
+
connection
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Reshape
|
2
|
+
# Custom error class for rescuing from all Shapeways errors
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Raised when Shapeways returns a 400 HTTP status code
|
6
|
+
class BadRequest < Error; end
|
7
|
+
|
8
|
+
# Raised when Shapeways returns a 401 HTTP status code
|
9
|
+
class Unauthorized < Error; end
|
10
|
+
|
11
|
+
# Raised when Shapeways returns a 403 HTTP status code
|
12
|
+
class Forbidden < Error; end
|
13
|
+
|
14
|
+
# Raised when Shapeways returns a 404 HTTP status code
|
15
|
+
class NotFound < Error; end
|
16
|
+
|
17
|
+
# Raised when Shapeways returns a 406 HTTP status code
|
18
|
+
class NotAcceptable < Error; end
|
19
|
+
|
20
|
+
# Raised when Shapeways returns a 422 HTTP status code
|
21
|
+
class UnprocessableEntity < Error; end
|
22
|
+
|
23
|
+
# Raised when Shapeways returns a 500 HTTP status code
|
24
|
+
class InternalServerError < Error; end
|
25
|
+
|
26
|
+
# Raised when Shapeways returns a 502 HTTP status code
|
27
|
+
class BadGateway < Error; end
|
28
|
+
|
29
|
+
# Raised when Shapeways returns a 503 HTTP status code
|
30
|
+
class ServiceUnavailable < Error; end
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
3
|
+
module Reshape
|
4
|
+
module Request
|
5
|
+
def get(path, options={}, raw=false, force_urlencoded=false)
|
6
|
+
request(:get, path, options, raw, force_urlencoded)
|
7
|
+
end
|
8
|
+
|
9
|
+
def post(path, options={}, raw=false, force_urlencoded=false)
|
10
|
+
request(:post, path, options, raw, force_urlencoded)
|
11
|
+
end
|
12
|
+
|
13
|
+
def put(path, options={}, raw=false, force_urlencoded=false)
|
14
|
+
request(:put, path, options, raw, force_urlencoded)
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete(path, options={}, raw=false, force_urlencoded=false)
|
18
|
+
request(:delete, path, options, raw, force_urlencoded)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def request(method, path, options, raw, force_urlencoded)
|
24
|
+
response = connection(raw, force_urlencoded).send(method) do |request|
|
25
|
+
case method
|
26
|
+
when :delete, :get
|
27
|
+
request.url(path, options)
|
28
|
+
when :patch, :post, :put
|
29
|
+
request.path = path
|
30
|
+
request.body = options unless options.empty?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if raw
|
35
|
+
response
|
36
|
+
else
|
37
|
+
response.body
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
data/lib/reshape.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'reshape/version'
|
2
|
+
require 'reshape/configuration'
|
3
|
+
require 'reshape/client'
|
4
|
+
require 'reshape/error'
|
5
|
+
|
6
|
+
module Reshape
|
7
|
+
extend Configuration
|
8
|
+
class << self
|
9
|
+
# Alias for Reshape::Client.new
|
10
|
+
#
|
11
|
+
# @return [Reshape::Client]
|
12
|
+
def new(options={})
|
13
|
+
Reshape::Client.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def respond_to?(method, include_private=false)
|
17
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/reshape.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'reshape/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "reshape"
|
8
|
+
gem.version = Reshape::VERSION
|
9
|
+
gem.authors = ["John Barton"]
|
10
|
+
gem.email = ["jb@phy5ics.com"]
|
11
|
+
gem.description = %q{A client for the Shapeways 3D printing API.}
|
12
|
+
gem.summary = %q{A client for the Shapeways 3D printing API.}
|
13
|
+
gem.homepage = "https://github.com/phy5ics/reshape"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'faraday', '~> 0.8.4'
|
21
|
+
gem.add_dependency 'faraday_middleware', '~> 0.8.4'
|
22
|
+
gem.add_dependency 'hashie', '~> 1.2'
|
23
|
+
gem.add_dependency 'multi_json', '~> 1.3'
|
24
|
+
gem.add_dependency 'simple_oauth'
|
25
|
+
|
26
|
+
gem.add_development_dependency 'json'
|
27
|
+
gem.add_development_dependency 'rake'
|
28
|
+
gem.add_development_dependency 'rspec'
|
29
|
+
gem.add_development_dependency 'simplecov'
|
30
|
+
gem.add_development_dependency 'webmock'
|
31
|
+
gem.add_development_dependency 'vcr'
|
32
|
+
|
33
|
+
end
|