simplewoo 0.0.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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/simplewoo/authentication.rb +35 -0
- data/lib/simplewoo/client/entity.rb +32 -0
- data/lib/simplewoo/client/match.rb +20 -0
- data/lib/simplewoo/client/personality.rb +31 -0
- data/lib/simplewoo/client/root.rb +10 -0
- data/lib/simplewoo/client/slider.rb +32 -0
- data/lib/simplewoo/client/tag.rb +32 -0
- data/lib/simplewoo/client/user.rb +87 -0
- data/lib/simplewoo/client.rb +33 -0
- data/lib/simplewoo/configuration.rb +34 -0
- data/lib/simplewoo/connection.rb +69 -0
- data/lib/simplewoo/error.rb +47 -0
- data/lib/simplewoo/request.rb +54 -0
- data/lib/simplewoo/version.rb +3 -0
- data/lib/simplewoo.rb +14 -0
- data/simplewoo.gemspec +37 -0
- data/spec/simplewoo/client/entity_spec.rb +34 -0
- data/spec/simplewoo/client/match_spec.rb +29 -0
- data/spec/simplewoo/client/personality_spec.rb +40 -0
- data/spec/simplewoo/client/root_spec.rb +53 -0
- data/spec/simplewoo/client/slider_spec.rb +37 -0
- data/spec/simplewoo/client/tag_spec.rb +35 -0
- data/spec/simplewoo/client/user_spec.rb +111 -0
- data/spec/simplewoo/error_spec.rb +61 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/support/mocks/bad_app_secret.json +1 -0
- data/spec/support/mocks/empty.json +3 -0
- data/spec/support/mocks/entities.json +1554 -0
- data/spec/support/mocks/entity.json +77 -0
- data/spec/support/mocks/match_results.json +96 -0
- data/spec/support/mocks/me.json +20 -0
- data/spec/support/mocks/root.json +10 -0
- data/spec/support/mocks/slider.json +44 -0
- data/spec/support/mocks/sliders.json +23 -0
- data/spec/support/mocks/tag.json +20 -0
- data/spec/support/mocks/updated_user.json +19 -0
- data/spec/support/mocks/user.json +19 -0
- metadata +312 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9ce5ee64a12d9b4dba315dfb6befedb743d7d956
|
4
|
+
data.tar.gz: 561cd207dea0eea08a393a7b0d6faa3f16e1d677
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b294c8dce8d1d0106f9ca4b97c6585d1fb8e22134ddea2c6e9d8757258bc237450613d4c92b0e683ffb4a40014e09cbbd654d1e0c7e3c7a8e8aa201d1183f1e9
|
7
|
+
data.tar.gz: 2fdbbdc9fa747de48bb6e08366d5bc13930ff4df48c03586979b895b775b6f78dbcb5c5c107e44413f9fe1341a4feeb2ddc7f73aa31ee4ec5bce617ed8734811
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jason Truluck
|
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,29 @@
|
|
1
|
+
# Simplewoo
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'simplewoo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install simplewoo
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# lib/simplewoo/authentication.rb
|
2
|
+
module Simplewoo
|
3
|
+
module Authentication
|
4
|
+
def basic_authenticated?
|
5
|
+
!!(self.email && self.password)
|
6
|
+
end
|
7
|
+
|
8
|
+
def token_authenticated?
|
9
|
+
!!(self.api_token)
|
10
|
+
end
|
11
|
+
|
12
|
+
def authenticated?
|
13
|
+
!!(basic_authenticated? || token_authenticated?)
|
14
|
+
end
|
15
|
+
|
16
|
+
def api_token
|
17
|
+
self.api_token ||= authenticate if authenticated?
|
18
|
+
end
|
19
|
+
|
20
|
+
# Authenticates the user with their email and password returning an api token
|
21
|
+
#
|
22
|
+
# @option args [String] email - the email of the user
|
23
|
+
# @option args [String] password - the password of the user
|
24
|
+
def authenticate(args = {})
|
25
|
+
self.email ||= args.delete(:email)
|
26
|
+
self.password ||= args.delete(:password)
|
27
|
+
|
28
|
+
unless token_authenticated?
|
29
|
+
self.api_token = me.access_token
|
30
|
+
end
|
31
|
+
|
32
|
+
self.api_token
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Simplewoo
|
2
|
+
class Client
|
3
|
+
module Entity
|
4
|
+
# Returns the matched entities for the slider
|
5
|
+
#
|
6
|
+
# @param [Integer] slider_id - The slider id that the entities are for
|
7
|
+
# @param [Integer] page_id - The page id that the entities are for
|
8
|
+
#
|
9
|
+
# @return [Hashie::Mash] Entities - list of entities by page
|
10
|
+
#
|
11
|
+
# @author Tom Prats
|
12
|
+
# Simplewoo::Client.entities(1)
|
13
|
+
def entities(slider_id, page_id=1, options = {})
|
14
|
+
get("/sliders/#{slider_id}/entities/page/#{page_id}", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns matched the entity
|
18
|
+
#
|
19
|
+
# @param [Integer] slider_id - The slider id that the entity is for
|
20
|
+
# @param [Integer] entity_id - The entity id that the entity is for
|
21
|
+
#
|
22
|
+
# @return [Hashie::Mash] Entity - the entity requested
|
23
|
+
#
|
24
|
+
# @author Tom Prats
|
25
|
+
# Simplewoo::Client.entity(1, 1)
|
26
|
+
def entity(slider_id, entity_id, options = {})
|
27
|
+
get("/sliders/#{slider_id}/entities/#{entity_id}", options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Simplewoo
|
2
|
+
class Client
|
3
|
+
module Match
|
4
|
+
# Returns the matched entities and matched personalities for the slider
|
5
|
+
#
|
6
|
+
# @param [Integer] id - The slider id that the matches are for
|
7
|
+
#
|
8
|
+
# @return [Hashie::Mash] matches - the matches for the slider
|
9
|
+
#
|
10
|
+
# @example Return the entity matches for a slider
|
11
|
+
# Simplewoo::Client.match_for_slider(1).entities
|
12
|
+
# @example Return the personality matches for a slider
|
13
|
+
# Simplewoo::Client.match_for_slider(1).personalities
|
14
|
+
def match_for_slider(id, options = {})
|
15
|
+
get("/sliders/#{id}/results", options)._embedded
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
module Simplewoo
|
3
|
+
class Client
|
4
|
+
module Personality
|
5
|
+
# Returns the personalities for the slider
|
6
|
+
#
|
7
|
+
# @param [Integer] id - The slider id that the matches are for
|
8
|
+
#
|
9
|
+
# @return [Hashie::Mash] personalities - the personalities for the slider
|
10
|
+
#
|
11
|
+
# @example Return the personalities for a slider
|
12
|
+
# Simplewoo::Client.personality_for_slider(1)
|
13
|
+
def personality_for_slider(id, options = {})
|
14
|
+
get("/sliders/#{id}/results", options)._embedded.personalities
|
15
|
+
end
|
16
|
+
|
17
|
+
# Resets the slider
|
18
|
+
#
|
19
|
+
# @param [Integer] id - The slider id that is reset
|
20
|
+
#
|
21
|
+
# @return status only
|
22
|
+
#
|
23
|
+
# @example Return the personalities for a slider
|
24
|
+
# Simplewoo::Client.personality_for_slider(1)
|
25
|
+
def reset(id, options = {})
|
26
|
+
delete("/sliders/#{id}/reset", options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Simplewoo
|
2
|
+
class Client
|
3
|
+
module Slider
|
4
|
+
# Return the sliders for the app you are on
|
5
|
+
#
|
6
|
+
# @note requires an authenticated Client instance (app_secret) _not_ an authenticated user
|
7
|
+
#
|
8
|
+
# @return [Hashie::Mash] sliders - the sliders available for the app
|
9
|
+
#
|
10
|
+
# @example Return the sliders for an app
|
11
|
+
# Simplewoo::Client.sliders
|
12
|
+
def sliders(options = {})
|
13
|
+
get("/sliders", options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Return the requested slider and its associated tags
|
17
|
+
#
|
18
|
+
# @note requires an authenticated Client instance (app_secret) _not_ an authenticated user
|
19
|
+
#
|
20
|
+
# @param [Integer] id - the id of the slider that you want to have returned
|
21
|
+
#
|
22
|
+
# @return [Hashie::Mash] slider - the slider that was requested
|
23
|
+
#
|
24
|
+
# @example Return a slider
|
25
|
+
# Simplewoo::Client.slider(1)
|
26
|
+
def slider(id, options = {})
|
27
|
+
get("/sliders/#{id}", options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Simplewoo
|
2
|
+
class Client
|
3
|
+
module Tag
|
4
|
+
# Returns the matched entities and matched personalities for the slider
|
5
|
+
#
|
6
|
+
# @param [Integer] slider_id - The slider id that the matches are for
|
7
|
+
# @param [Integer] tag_id - The tag id that the matches are for
|
8
|
+
# @param [Boolean] value - The tag id that the matches are for
|
9
|
+
#
|
10
|
+
# @author Carson Wright
|
11
|
+
# @author Chris Preisinger
|
12
|
+
# Simplewoo::Client.add_tag(1, 1, true)
|
13
|
+
def add_tag(slider_id, tag_id, value, options = {})
|
14
|
+
options.merge!(me: value)
|
15
|
+
post("/sliders/#{slider_id}/tags/#{tag_id}/add", options)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns a tag
|
19
|
+
#
|
20
|
+
# @param [Integer] tag_id - The tag id you want returned
|
21
|
+
#
|
22
|
+
# @return [Hashie::Mash] Tag - the requested tag
|
23
|
+
#
|
24
|
+
# @author Carson Wright
|
25
|
+
# Simplewoo::Client.tag(1, 1, true)
|
26
|
+
def tag(tag_id, options = {})
|
27
|
+
get("/tags/#{tag_id}", options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Simplewoo
|
2
|
+
class Client
|
3
|
+
module User
|
4
|
+
# Create a user on the core api
|
5
|
+
#
|
6
|
+
# @param [String] email - the email of the user
|
7
|
+
# @param [String] password - the password of the user
|
8
|
+
# @param [String] password_confirmation - the password_confirmation of the user
|
9
|
+
# @param [String] birthday - the birthday of the user
|
10
|
+
# @param [String] first_name - the first name of the user
|
11
|
+
# @param [String] last_name - the first name of the user
|
12
|
+
#
|
13
|
+
# @option options [String] bio - The users bio
|
14
|
+
# @option options [String] image - The users image
|
15
|
+
#
|
16
|
+
# @return [Hashie::Mash] user the user created by the request
|
17
|
+
#
|
18
|
+
# @example Create a user
|
19
|
+
# Simplewoo.create_user({
|
20
|
+
# :email => "some@example.com",
|
21
|
+
# :password => "password",
|
22
|
+
# :password_confirmation => "password",
|
23
|
+
# :birthday => "1988-01-01",
|
24
|
+
# :first_name => "Johnny",
|
25
|
+
# :last_name => "Test"
|
26
|
+
# })
|
27
|
+
def create_user(email, password, password_confirmation, birthday, first_name, last_name, options = {})
|
28
|
+
options.merge!({
|
29
|
+
:email => email,
|
30
|
+
:password => password,
|
31
|
+
:password_confirmation => password_confirmation,
|
32
|
+
:birthday => birthday,
|
33
|
+
:first_name => first_name,
|
34
|
+
:last_name => last_name
|
35
|
+
})
|
36
|
+
|
37
|
+
result = post("/users", { :user => options })
|
38
|
+
# TODO we should really make this core method return an api_token as well and use that instead
|
39
|
+
authenticate({:email => email, :password => password })
|
40
|
+
result
|
41
|
+
end
|
42
|
+
|
43
|
+
# Update a user on the core api
|
44
|
+
#
|
45
|
+
# @note This method requires an authenticated user via email + password or api_token
|
46
|
+
#
|
47
|
+
# @option options [String] email - the email of the user
|
48
|
+
# @option options [String] password - the password of the user
|
49
|
+
# @option options [String] password_confirmation - the password_confirmation of the user
|
50
|
+
# @option options [String] birthday - the birthday of the user
|
51
|
+
# @option options [String] first_name - the first name of the user
|
52
|
+
# @option options [String] last_name - the first name of the user
|
53
|
+
# @option options [String] bio - The users bio
|
54
|
+
# @option options [String] image - The users image
|
55
|
+
#
|
56
|
+
# @return [Hashie::Mash] user the user updated by the request
|
57
|
+
#
|
58
|
+
# @example Update a user
|
59
|
+
# Simplewoo.update_user({
|
60
|
+
# :email => "some_new_email@example.com"
|
61
|
+
# })
|
62
|
+
def update_user(options = {})
|
63
|
+
if authenticated?
|
64
|
+
put("/users/me", { :user => options })
|
65
|
+
else
|
66
|
+
raise "No authorized user."
|
67
|
+
end
|
68
|
+
end
|
69
|
+
alias :reset_password :update_user
|
70
|
+
|
71
|
+
# Returns the currently authenticated user
|
72
|
+
#
|
73
|
+
# @note This method requires an authenticated user via email + password or api_token
|
74
|
+
#
|
75
|
+
# @example Return the user
|
76
|
+
# Simplewoo.me
|
77
|
+
def me
|
78
|
+
if authenticated?
|
79
|
+
get("/users/me")
|
80
|
+
else
|
81
|
+
raise "No authorized user."
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# lib/simplewoo/client.rb
|
2
|
+
# require base modules
|
3
|
+
require "simplewoo/authentication"
|
4
|
+
require "simplewoo/connection"
|
5
|
+
require "simplewoo/request"
|
6
|
+
# require client modules in lib/simplewoo/client
|
7
|
+
Dir[File.expand_path("../client/*.rb", __FILE__)].each {|f| require f }
|
8
|
+
|
9
|
+
module Simplewoo
|
10
|
+
class Client
|
11
|
+
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
options = Simplewoo.options.merge(options)
|
15
|
+
|
16
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
17
|
+
send("#{key}=", options[key])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
include Simplewoo::Authentication
|
22
|
+
include Simplewoo::Connection
|
23
|
+
include Simplewoo::Request
|
24
|
+
|
25
|
+
include Simplewoo::Client::Root
|
26
|
+
include Simplewoo::Client::User
|
27
|
+
include Simplewoo::Client::Slider
|
28
|
+
include Simplewoo::Client::Match
|
29
|
+
include Simplewoo::Client::Personality
|
30
|
+
include Simplewoo::Client::Tag
|
31
|
+
include Simplewoo::Client::Entity
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# lib/simplewoo/configuration.rb#
|
2
|
+
module Simplewoo
|
3
|
+
module Configuration
|
4
|
+
# TODO try to remove redis
|
5
|
+
VALID_OPTIONS_KEYS = [
|
6
|
+
:app_secret,
|
7
|
+
:api_server_host,
|
8
|
+
:api_endpoint,
|
9
|
+
:trusted,
|
10
|
+
:ssl,
|
11
|
+
:email,
|
12
|
+
:password,
|
13
|
+
:api_token,
|
14
|
+
:debug
|
15
|
+
]
|
16
|
+
|
17
|
+
attr_accessor(*VALID_OPTIONS_KEYS)
|
18
|
+
|
19
|
+
def configure
|
20
|
+
yield self
|
21
|
+
end
|
22
|
+
|
23
|
+
def options
|
24
|
+
VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def reset!
|
28
|
+
VALID_OPTIONS_KEYS.each {|key| class_eval(%Q{key = nil}) }
|
29
|
+
self.trusted = "false"
|
30
|
+
self.ssl = true
|
31
|
+
self.debug = false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# lib/simplewoo/connection.rb
|
2
|
+
require "json"
|
3
|
+
require "faraday_middleware"
|
4
|
+
require "simplewoo/error"
|
5
|
+
require "pry"
|
6
|
+
|
7
|
+
module Simplewoo
|
8
|
+
module Connection
|
9
|
+
def connection(options = {})
|
10
|
+
connection ||= Faraday.new(options) do |faraday|
|
11
|
+
faraday.request :url_encoded
|
12
|
+
if basic_authenticated?
|
13
|
+
faraday.request :basic_auth, self.email, self.password
|
14
|
+
elsif token_authenticated?
|
15
|
+
faraday.request :basic_auth, "", self.api_token
|
16
|
+
end
|
17
|
+
faraday.use AppSecretMiddleware, app_secret: self.app_secret
|
18
|
+
faraday.use TrustedAppMiddleware, trusted: self.trusted
|
19
|
+
faraday.response :logger if self.debug
|
20
|
+
faraday.use ErrorMiddleware
|
21
|
+
faraday.response :mashify
|
22
|
+
faraday.response :json, :content_type => /\bjson$/
|
23
|
+
faraday.adapter Faraday.default_adapter
|
24
|
+
end
|
25
|
+
|
26
|
+
connection
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
# Middleware for inserting the app secret header into requests
|
31
|
+
class AppSecretMiddleware < Faraday::Middleware
|
32
|
+
def initialize(app, options = {})
|
33
|
+
@app = app
|
34
|
+
@options = options
|
35
|
+
end
|
36
|
+
|
37
|
+
def call(env)
|
38
|
+
env[:request_headers]["Woofound-App-Secret"] = @options[:app_secret]
|
39
|
+
@app.call(env)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
# Middleware for inserting the trusted header into requests
|
43
|
+
class TrustedAppMiddleware < Faraday::Middleware
|
44
|
+
def initialize(app, options = {})
|
45
|
+
@app = app
|
46
|
+
@options = options
|
47
|
+
end
|
48
|
+
|
49
|
+
def call(env)
|
50
|
+
env[:request_headers]["Woofound-Use-Trusted"] = @options[:trusted].to_s
|
51
|
+
@app.call(env)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
# Middleware for responding to Errors returned from the api
|
55
|
+
class ErrorMiddleware < Faraday::Middleware
|
56
|
+
def initialize(app)
|
57
|
+
@app = app
|
58
|
+
end
|
59
|
+
|
60
|
+
def call(env)
|
61
|
+
@app.call(env).on_complete do |env|
|
62
|
+
if error = Simplewoo::Error.from(env[:response])
|
63
|
+
raise error
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# lib/simplewoo/error.rb
|
2
|
+
module Simplewoo
|
3
|
+
class Error < StandardError
|
4
|
+
attr_accessor :response
|
5
|
+
|
6
|
+
def self.from(response)
|
7
|
+
status = response.status
|
8
|
+
|
9
|
+
if klass = case status
|
10
|
+
when 400 then Simplewoo::BadRequest
|
11
|
+
when 401 then Simplewoo::Unauthorized
|
12
|
+
when 404 then Simplewoo::NotFound
|
13
|
+
when 422 then Simplewoo::UnprocessableEntity
|
14
|
+
end
|
15
|
+
|
16
|
+
klass.new(response)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(response)
|
21
|
+
@response = response
|
22
|
+
super(error_message)
|
23
|
+
end
|
24
|
+
|
25
|
+
def errors
|
26
|
+
response.body
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def error_message
|
31
|
+
message = "#{response.env[:method].upcase} "
|
32
|
+
message << "#{response.env[:url].to_s} | "
|
33
|
+
message << "#{response.status}: "
|
34
|
+
message << "#{response.body.map{|k,v| "#{k}: #{v.first}"}.join(", ")}"
|
35
|
+
message
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Raised when Woofound Core Api returns a 400 HTTP status code
|
40
|
+
class BadRequest < Error; end
|
41
|
+
# Raised when Woofound Core Api returns a 401 HTTP status code
|
42
|
+
class Unauthorized < Error; end
|
43
|
+
# Raised when Woofound Core Api returns a 404 HTTP status code
|
44
|
+
class NotFound < Error; end
|
45
|
+
# Raised when Woofound Core Api returns a 422 HTTP status code
|
46
|
+
class UnprocessableEntity < Error; end
|
47
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# lib/simplewoo/request.rb
|
2
|
+
module Simplewoo
|
3
|
+
module Request
|
4
|
+
def get(path, options = {})
|
5
|
+
request(:get, path, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def post(path, options = {})
|
9
|
+
request(:post, path, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def put(path, options={})
|
13
|
+
request(:put, path, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete(path, options={})
|
17
|
+
request(:delete, path, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def last_response
|
21
|
+
@last_response
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def build_endpoint
|
26
|
+
endpoint = ssl ? "https://" : "http://"
|
27
|
+
endpoint << self.api_server_host
|
28
|
+
self.api_endpoint = endpoint
|
29
|
+
end
|
30
|
+
|
31
|
+
def request(method, path, options = {})
|
32
|
+
url = options.delete(:endpoint) || build_endpoint
|
33
|
+
|
34
|
+
connection_options = {}.merge!(:url => url)
|
35
|
+
|
36
|
+
response = connection(connection_options).send(method) do |request|
|
37
|
+
case method
|
38
|
+
when :get
|
39
|
+
request.url(path, options)
|
40
|
+
when :post
|
41
|
+
request.url(path, options)
|
42
|
+
when :put
|
43
|
+
request.url(path, options)
|
44
|
+
when :delete
|
45
|
+
request.url(path, options)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@last_response = response
|
50
|
+
response.body
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/lib/simplewoo.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "simplewoo/version"
|
2
|
+
require "simplewoo/configuration"
|
3
|
+
require "simplewoo/client"
|
4
|
+
|
5
|
+
module Simplewoo
|
6
|
+
extend Configuration
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Alias method for Simplewoo::Client.new
|
10
|
+
def new(options = {})
|
11
|
+
Simplewoo::Client.new(options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/simplewoo.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simplewoo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simplewoo"
|
8
|
+
spec.version = Simplewoo::VERSION
|
9
|
+
spec.authors = ["Jason Truluck", "Carson Wright", "Tom Prats", "Sam Boyd", "Chris Preisinger"]
|
10
|
+
spec.email = ["jason.truluck@gmail.com", "carsonnwright@gmail.com", "tom@tomprats.com", "sam@woofound.com", "chris@woofound.com"]
|
11
|
+
spec.description = %q{Woofound Client Gem}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "faraday", "~> 0.8.0"
|
22
|
+
spec.add_dependency "faraday_middleware", "~> 0.9.0"
|
23
|
+
spec.add_dependency "hashie", "~> 2.0.0"
|
24
|
+
spec.add_dependency "multi_json", "~> 1.8.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.1.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 2.14.0"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
spec.add_development_dependency "binding_of_caller"
|
31
|
+
spec.add_development_dependency "webmock", "~> 1.13.0"
|
32
|
+
spec.add_development_dependency "simplecov", "~> 0.7.0"
|
33
|
+
spec.add_development_dependency "coveralls", "~> 0.7.0"
|
34
|
+
spec.add_development_dependency "yard", "~> 0.8.0.0"
|
35
|
+
spec.add_development_dependency "redcarpet", "~> 3.0.0"
|
36
|
+
end
|
37
|
+
|