evrythng 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.
- data/lib/evrythng/client/collections.rb +17 -0
- data/lib/evrythng/client/thngs.rb +38 -0
- data/lib/evrythng/client.rb +2 -2
- data/lib/evrythng/configuration.rb +11 -5
- data/lib/evrythng/connection.rb +3 -2
- data/lib/evrythng/request.rb +2 -6
- data/lib/evrythng/version.rb +1 -1
- data/lib/faraday/request/basic_authentication.rb +15 -0
- metadata +69 -76
- data/lib/evrythng/client/things.rb +0 -21
@@ -16,6 +16,23 @@ module Evrythng
|
|
16
16
|
response = get('collections', options)
|
17
17
|
format.to_s.downcase == 'xml' ? response['collections'] : response
|
18
18
|
end
|
19
|
+
|
20
|
+
# Creates a collection
|
21
|
+
#
|
22
|
+
# @format :json, :xml
|
23
|
+
# @authenticated true
|
24
|
+
# @rate_limited false
|
25
|
+
# @param name [String] The name of collection.
|
26
|
+
# @param description [String] The description of collection.
|
27
|
+
# @param options [Hash] A customizable set of options.
|
28
|
+
# @return [Hashie::Rash] The created collection.
|
29
|
+
# @see http://dev.evrythng.net/doc/post/collections
|
30
|
+
# @example Create the authenticating user's collection
|
31
|
+
# Evrythng.collection_create("This is a new collection!", "Here comes the description.")
|
32
|
+
def collection_create(name, description=nil, options={})
|
33
|
+
response = post('collections', options.merge(:collection => { :name => name, :description => description }))
|
34
|
+
format.to_s.downcase == 'xml' ? response['collection'] : response
|
35
|
+
end
|
19
36
|
end
|
20
37
|
end
|
21
38
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Evrythng
|
2
|
+
class Client
|
3
|
+
# Defines methods related to thngs
|
4
|
+
module Thngs
|
5
|
+
# Returns a list of thngs
|
6
|
+
#
|
7
|
+
# @format :json, :xml
|
8
|
+
# @authenticated true
|
9
|
+
# @rate_limited true
|
10
|
+
# @param options [Hash] A customizable set of options.
|
11
|
+
# @return [Hashie::Rash] The requested list of thngs.
|
12
|
+
# @see http://developer.evrythng.net/thngs
|
13
|
+
# @example Return the list of thngs
|
14
|
+
# Evrythng.thngs
|
15
|
+
def thngs(options={})
|
16
|
+
response = get('thngs', options)
|
17
|
+
format.to_s.downcase == 'xml' ? response['thngs'] : response
|
18
|
+
end
|
19
|
+
|
20
|
+
# Creates a thng
|
21
|
+
#
|
22
|
+
# @format :json, :xml
|
23
|
+
# @authenticated true
|
24
|
+
# @rate_limited false
|
25
|
+
# @param identifier [String] The identifier of thng.
|
26
|
+
# @param description [String] The description of thng.
|
27
|
+
# @param options [Hash] A customizable set of options.
|
28
|
+
# @return [Hashie::Rash] The created thng.
|
29
|
+
# @see http://developer.evrythng.net/thngs
|
30
|
+
# @example Create the authenticating user's thng
|
31
|
+
# Evrythng.thng_create("my.test.thng", "Here comes the description.")
|
32
|
+
def thng_create(identifier, description=nil, options={})
|
33
|
+
response = post('thngs', options.merge(:thng => { :identifier => identifier, :description => description }))
|
34
|
+
format.to_s.downcase == 'xml' ? response['thng'] : response
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/evrythng/client.rb
CHANGED
@@ -4,10 +4,10 @@ module Evrythng
|
|
4
4
|
# Require client method modules after initializing the Client class in
|
5
5
|
# order to avoid a superclass mismatch error, allowing those modules to be
|
6
6
|
# Client-namespaced.
|
7
|
-
require 'evrythng/client/
|
7
|
+
require 'evrythng/client/thngs'
|
8
8
|
require 'evrythng/client/collections'
|
9
9
|
|
10
|
-
include Evrythng::Client::
|
10
|
+
include Evrythng::Client::Thngs
|
11
11
|
include Evrythng::Client::Collections
|
12
12
|
end
|
13
13
|
end
|
@@ -9,6 +9,8 @@ module Evrythng
|
|
9
9
|
:adapter,
|
10
10
|
:consumer_key,
|
11
11
|
:consumer_secret,
|
12
|
+
:username,
|
13
|
+
:password,
|
12
14
|
:api_endpoint,
|
13
15
|
:format,
|
14
16
|
:gateway,
|
@@ -36,8 +38,14 @@ module Evrythng
|
|
36
38
|
# By default, don't set an application secret
|
37
39
|
DEFAULT_CONSUMER_SECRET = nil
|
38
40
|
|
41
|
+
# By default, don't set a username
|
42
|
+
DEFAULT_USERNAME = nil
|
43
|
+
|
44
|
+
# By default, don't set password
|
45
|
+
DEFAULT_PASSWORD = nil
|
46
|
+
|
39
47
|
# The endpoint that will be used to connect if none is set
|
40
|
-
DEFAULT_ENDPOINT = 'http://evrythng.net
|
48
|
+
DEFAULT_ENDPOINT = 'http://api.evrythng.net'.freeze
|
41
49
|
|
42
50
|
# The response format appended to the path and sent in the 'Accept' header if none is set
|
43
51
|
#
|
@@ -53,9 +61,6 @@ module Evrythng
|
|
53
61
|
# By default, don't use a proxy server
|
54
62
|
DEFAULT_PROXY = nil
|
55
63
|
|
56
|
-
# The search endpoint that will be used to connect if none is set
|
57
|
-
DEFAULT_SEARCH_ENDPOINT = 'http://evrythng.net/api/v1/search'.freeze
|
58
|
-
|
59
64
|
# The user agent that will be sent to the API endpoint if none is set
|
60
65
|
DEFAULT_USER_AGENT = "Evrythng Ruby Gem #{Evrythng::VERSION}".freeze
|
61
66
|
|
@@ -86,12 +91,13 @@ module Evrythng
|
|
86
91
|
self.adapter = DEFAULT_ADAPTER
|
87
92
|
self.consumer_key = DEFAULT_CONSUMER_KEY
|
88
93
|
self.consumer_secret = DEFAULT_CONSUMER_SECRET
|
94
|
+
self.username = DEFAULT_USERNAME
|
95
|
+
self.password = DEFAULT_PASSWORD
|
89
96
|
self.api_endpoint = DEFAULT_ENDPOINT
|
90
97
|
self.format = DEFAULT_FORMAT
|
91
98
|
self.oauth_token = DEFAULT_OAUTH_TOKEN
|
92
99
|
self.oauth_token_secret = DEFAULT_OAUTH_TOKEN_SECRET
|
93
100
|
self.proxy = DEFAULT_PROXY
|
94
|
-
self.search_endpoint = DEFAULT_SEARCH_ENDPOINT
|
95
101
|
self.user_agent = DEFAULT_USER_AGENT
|
96
102
|
self.gateway = DEFAULT_GATEWAY
|
97
103
|
self
|
data/lib/evrythng/connection.rb
CHANGED
@@ -2,6 +2,7 @@ require 'faraday_middleware'
|
|
2
2
|
require 'faraday/request/multipart_with_file'
|
3
3
|
require 'faraday/request/gateway'
|
4
4
|
require 'faraday/request/evrythng_oauth'
|
5
|
+
require 'faraday/request/basic_authentication'
|
5
6
|
require 'faraday/response/raise_http_4xx'
|
6
7
|
require 'faraday/response/raise_http_5xx'
|
7
8
|
|
@@ -12,7 +13,7 @@ module Evrythng
|
|
12
13
|
|
13
14
|
def connection(raw=false)
|
14
15
|
options = {
|
15
|
-
:headers => {'Accept' => "application
|
16
|
+
:headers => {'Accept' => "application/vnd.evrythng-v1+json", 'User-Agent' => user_agent},
|
16
17
|
:proxy => proxy,
|
17
18
|
:ssl => {:verify => false},
|
18
19
|
:url => api_endpoint,
|
@@ -20,8 +21,8 @@ module Evrythng
|
|
20
21
|
|
21
22
|
Faraday.new(options) do |builder|
|
22
23
|
builder.use Faraday::Request::MultipartWithFile
|
23
|
-
builder.use Faraday::Request::EvrythngOAuth, authentication if authenticated?
|
24
24
|
builder.use Faraday::Request::Multipart
|
25
|
+
builder.use Faraday::Request::BasicAuthentication, username, password
|
25
26
|
builder.use Faraday::Request::UrlEncoded
|
26
27
|
builder.use Faraday::Request::Gateway, gateway if gateway
|
27
28
|
builder.use Faraday::Response::RaiseHttp4xx
|
data/lib/evrythng/request.rb
CHANGED
@@ -28,17 +28,13 @@ module Evrythng
|
|
28
28
|
response = connection(raw).send(method) do |request|
|
29
29
|
case method
|
30
30
|
when :get, :delete
|
31
|
-
request.url(
|
31
|
+
request.url(path, options)
|
32
32
|
when :post, :put
|
33
|
-
request.path =
|
33
|
+
request.path = path
|
34
34
|
request.body = options unless options.empty?
|
35
35
|
end
|
36
36
|
end
|
37
37
|
raw ? response : response.body
|
38
38
|
end
|
39
|
-
|
40
|
-
def formatted_path(path)
|
41
|
-
[path, format].compact.join('.')
|
42
|
-
end
|
43
39
|
end
|
44
40
|
end
|
data/lib/evrythng/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Request::BasicAuthentication < Faraday::Middleware
|
5
|
+
def initialize(app, login, pass)
|
6
|
+
super(app)
|
7
|
+
@header_value = "Basic #{Base64.encode64([login, pass].join(':')).gsub("\n", '')}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
env[:request_headers]['Authorization'] = @header_value
|
12
|
+
@app.call(env)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,114 +1,110 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: evrythng
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- beawesomeinstead
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-07-18 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: yard
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70277242139060 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
18
|
+
requirements:
|
21
19
|
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.6'
|
24
22
|
type: :development
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: hashie
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: *70277242139060
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hashie
|
27
|
+
requirement: &70277242138440 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
29
|
+
requirements:
|
32
30
|
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
31
|
+
- !ruby/object:Gem::Version
|
34
32
|
version: 1.0.0
|
35
33
|
type: :runtime
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: faraday
|
39
34
|
prerelease: false
|
40
|
-
|
35
|
+
version_requirements: *70277242138440
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: faraday
|
38
|
+
requirement: &70277242137960 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
|
-
requirements:
|
40
|
+
requirements:
|
43
41
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
42
|
+
- !ruby/object:Gem::Version
|
45
43
|
version: 0.6.1
|
46
44
|
type: :runtime
|
47
|
-
version_requirements: *id003
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: faraday_middleware
|
50
45
|
prerelease: false
|
51
|
-
|
46
|
+
version_requirements: *70277242137960
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: faraday_middleware
|
49
|
+
requirement: &70277242137460 !ruby/object:Gem::Requirement
|
52
50
|
none: false
|
53
|
-
requirements:
|
51
|
+
requirements:
|
54
52
|
- - ~>
|
55
|
-
- !ruby/object:Gem::Version
|
53
|
+
- !ruby/object:Gem::Version
|
56
54
|
version: 0.6.3
|
57
55
|
type: :runtime
|
58
|
-
version_requirements: *id004
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
-
name: multi_json
|
61
56
|
prerelease: false
|
62
|
-
|
57
|
+
version_requirements: *70277242137460
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: multi_json
|
60
|
+
requirement: &70277242137000 !ruby/object:Gem::Requirement
|
63
61
|
none: false
|
64
|
-
requirements:
|
62
|
+
requirements:
|
65
63
|
- - ~>
|
66
|
-
- !ruby/object:Gem::Version
|
64
|
+
- !ruby/object:Gem::Version
|
67
65
|
version: 1.0.0
|
68
66
|
type: :runtime
|
69
|
-
version_requirements: *id005
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: multi_xml
|
72
67
|
prerelease: false
|
73
|
-
|
68
|
+
version_requirements: *70277242137000
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: multi_xml
|
71
|
+
requirement: &70277242136520 !ruby/object:Gem::Requirement
|
74
72
|
none: false
|
75
|
-
requirements:
|
73
|
+
requirements:
|
76
74
|
- - ~>
|
77
|
-
- !ruby/object:Gem::Version
|
75
|
+
- !ruby/object:Gem::Version
|
78
76
|
version: 0.2.0
|
79
77
|
type: :runtime
|
80
|
-
version_requirements: *id006
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
name: rash
|
83
78
|
prerelease: false
|
84
|
-
|
79
|
+
version_requirements: *70277242136520
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rash
|
82
|
+
requirement: &70277242136060 !ruby/object:Gem::Requirement
|
85
83
|
none: false
|
86
|
-
requirements:
|
84
|
+
requirements:
|
87
85
|
- - ~>
|
88
|
-
- !ruby/object:Gem::Version
|
86
|
+
- !ruby/object:Gem::Version
|
89
87
|
version: 0.3.0
|
90
88
|
type: :runtime
|
91
|
-
version_requirements: *id007
|
92
|
-
- !ruby/object:Gem::Dependency
|
93
|
-
name: simple_oauth
|
94
89
|
prerelease: false
|
95
|
-
|
90
|
+
version_requirements: *70277242136060
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: simple_oauth
|
93
|
+
requirement: &70277242135560 !ruby/object:Gem::Requirement
|
96
94
|
none: false
|
97
|
-
requirements:
|
95
|
+
requirements:
|
98
96
|
- - ~>
|
99
|
-
- !ruby/object:Gem::Version
|
97
|
+
- !ruby/object:Gem::Version
|
100
98
|
version: 0.1.5
|
101
99
|
type: :runtime
|
102
|
-
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70277242135560
|
103
102
|
description: A Ruby wrapper for the Evrythng API.
|
104
103
|
email: graf.otodrakula@gmail.com
|
105
104
|
executables: []
|
106
|
-
|
107
105
|
extensions: []
|
108
|
-
|
109
106
|
extra_rdoc_files: []
|
110
|
-
|
111
|
-
files:
|
107
|
+
files:
|
112
108
|
- README
|
113
109
|
- Rakefile
|
114
110
|
- evrythng.gemspec
|
@@ -117,12 +113,13 @@ files:
|
|
117
113
|
- lib/evrythng/authentication.rb
|
118
114
|
- lib/evrythng/client.rb
|
119
115
|
- lib/evrythng/client/collections.rb
|
120
|
-
- lib/evrythng/client/
|
116
|
+
- lib/evrythng/client/thngs.rb
|
121
117
|
- lib/evrythng/configuration.rb
|
122
118
|
- lib/evrythng/connection.rb
|
123
119
|
- lib/evrythng/error.rb
|
124
120
|
- lib/evrythng/request.rb
|
125
121
|
- lib/evrythng/version.rb
|
122
|
+
- lib/faraday/request/basic_authentication.rb
|
126
123
|
- lib/faraday/request/evrythng_oauth.rb
|
127
124
|
- lib/faraday/request/gateway.rb
|
128
125
|
- lib/faraday/request/multipart_with_file.rb
|
@@ -131,30 +128,26 @@ files:
|
|
131
128
|
- lib/faraday/response/raise_http_5xx.rb
|
132
129
|
homepage: http://github.com/bai/evrythng
|
133
130
|
licenses: []
|
134
|
-
|
135
131
|
post_install_message:
|
136
132
|
rdoc_options: []
|
137
|
-
|
138
|
-
require_paths:
|
133
|
+
require_paths:
|
139
134
|
- lib
|
140
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
136
|
none: false
|
142
|
-
requirements:
|
143
|
-
- -
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version:
|
146
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ! '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
142
|
none: false
|
148
|
-
requirements:
|
149
|
-
- -
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
version:
|
143
|
+
requirements:
|
144
|
+
- - ! '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
152
147
|
requirements: []
|
153
|
-
|
154
148
|
rubyforge_project:
|
155
149
|
rubygems_version: 1.8.5
|
156
150
|
signing_key:
|
157
151
|
specification_version: 3
|
158
152
|
summary: A Ruby wrapper for the Evrythng API.
|
159
153
|
test_files: []
|
160
|
-
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Evrythng
|
2
|
-
class Client
|
3
|
-
# Defines methods related to things
|
4
|
-
module Things
|
5
|
-
# Returns a list of things
|
6
|
-
#
|
7
|
-
# @format :json, :xml
|
8
|
-
# @authenticated true
|
9
|
-
# @rate_limited true
|
10
|
-
# @param options [Hash] A customizable set of options.
|
11
|
-
# @return [Hashie::Rash] The requested list of things.
|
12
|
-
# @see http://dev.evrythng.net/doc/get/things
|
13
|
-
# @example Return the list of things
|
14
|
-
# Evrythng.things
|
15
|
-
def things(options={})
|
16
|
-
response = get('things', options)
|
17
|
-
format.to_s.downcase == 'xml' ? response['things'] : response
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|