consumerable 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/consumerable.rb +13 -0
- data/lib/consumerable/configuration.rb +6 -1
- data/lib/consumerable/connection.rb +9 -6
- data/lib/consumerable/creatable.rb +2 -1
- data/lib/consumerable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8263ee28864c261b04aaed6db3e02437df28cc59
|
4
|
+
data.tar.gz: 49f16b965fbdb53cb750e822ed6d8e58a4a1db1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7f90eaaf33614356284717ecef4798fa50bbd6af3c927adf431c57c8ec7b14bacbe311da85f0e79ae3cbfccd048297510b9ed02fa572928cf28171c6b4f9e6a
|
7
|
+
data.tar.gz: 27cec036c8888d0d6a6fa3b8146bd724b5bada72fd226d24b4c236f1eb082b5540aa60f04fca483bdd96fd3f1d83191bd185c61a9e86d1b9cae26cd88566bd9b
|
data/lib/consumerable.rb
CHANGED
@@ -7,12 +7,25 @@ module Consumerable
|
|
7
7
|
attr_accessor :configuration
|
8
8
|
end
|
9
9
|
|
10
|
+
def self.log(message)
|
11
|
+
if configuration && configuration.perform_logging?
|
12
|
+
configuration.logger.info("CONSUMERABLE: #{message}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
10
16
|
def self.configure
|
11
17
|
self.configuration = Consumerable::Configuration.new
|
12
18
|
yield self.configuration
|
13
19
|
self.configuration
|
14
20
|
end
|
15
21
|
|
22
|
+
def self.content_type_string(content_type)
|
23
|
+
{
|
24
|
+
json: 'application/json',
|
25
|
+
xml: 'application/xml'
|
26
|
+
}.fetch(content_type)
|
27
|
+
end
|
28
|
+
|
16
29
|
eager_autoload do
|
17
30
|
autoload :Associations
|
18
31
|
autoload :Configuration
|
@@ -1,10 +1,15 @@
|
|
1
1
|
module Consumerable
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :logger, :endpoint, :api_version, :content_type,
|
4
|
-
:accept_header, :basic_auth_username, :basic_auth_password
|
4
|
+
:accept_header, :basic_auth_username, :basic_auth_password,
|
5
|
+
:perform_logging
|
5
6
|
|
6
7
|
def logger
|
7
8
|
@logger ||= Logger.new(STDOUT)
|
8
9
|
end
|
10
|
+
|
11
|
+
def perform_logging?
|
12
|
+
!!perform_logging
|
13
|
+
end
|
9
14
|
end
|
10
15
|
end
|
@@ -4,21 +4,24 @@ module Consumerable
|
|
4
4
|
class Connection
|
5
5
|
|
6
6
|
def self.get(path, options = {})
|
7
|
+
Consumerable.log "GET #{path} with #{options}"
|
7
8
|
connection.get(path, options).body
|
8
9
|
end
|
9
10
|
|
10
11
|
def self.post(path, options = {})
|
11
|
-
Consumerable.
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
Consumerable.log "POST #{path} with #{options}"
|
13
|
+
connection.post(path, options).tap do |response|
|
14
|
+
Consumerable.log "RESPONDED WITH: #{response.body}"
|
15
|
+
end.body
|
15
16
|
end
|
16
17
|
|
17
18
|
def self.patch(path, options = {})
|
19
|
+
Consumerable.log "PATCH #{path} with #{options}"
|
18
20
|
connection.patch(path, options).success?
|
19
21
|
end
|
20
22
|
|
21
23
|
def self.delete(path, options = {})
|
24
|
+
Consumerable.log "DELETE #{path} with #{options}"
|
22
25
|
connection.delete(path, options).success?
|
23
26
|
end
|
24
27
|
|
@@ -27,12 +30,12 @@ module Consumerable
|
|
27
30
|
url: Consumerable.configuration.endpoint,
|
28
31
|
headers: {
|
29
32
|
accept: Consumerable.configuration.accept_header,
|
30
|
-
content_type: Consumerable.
|
33
|
+
content_type: Consumerable.
|
34
|
+
content_type_string(Consumerable.configuration.content_type)
|
31
35
|
}
|
32
36
|
) do |builder|
|
33
37
|
builder.request Consumerable.configuration.content_type
|
34
38
|
builder.response Consumerable.configuration.content_type
|
35
|
-
builder.response :raise_error
|
36
39
|
builder.use Faraday::Response::Mashify
|
37
40
|
builder.adapter :typhoeus
|
38
41
|
end.tap do |connection|
|
@@ -33,7 +33,8 @@ module Consumerable
|
|
33
33
|
def create_record
|
34
34
|
self.attributes =
|
35
35
|
Consumerable::Connection.post(
|
36
|
-
_inject_path_params(create_path), attributes_for_api.except(:id)
|
36
|
+
_inject_path_params(create_path), attributes_for_api.except(:id).
|
37
|
+
delete_if { |k, v| v.blank? }
|
37
38
|
)
|
38
39
|
end
|
39
40
|
end
|
data/lib/consumerable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consumerable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Beedle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|