consumerable 0.1.1 → 0.2.0

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: dcdd359b35c8d18c17b44b2c813442015734c12a
4
- data.tar.gz: 2523b9689d42fbaa9f608b6fe8984df4ad52184f
3
+ metadata.gz: 8263ee28864c261b04aaed6db3e02437df28cc59
4
+ data.tar.gz: 49f16b965fbdb53cb750e822ed6d8e58a4a1db1c
5
5
  SHA512:
6
- metadata.gz: 7b66b049340efb5c9789cd75a0245b7f5863f5761566fa526d38a36e126646eb999d404a32996bb3317a771e2a79d54d93d192c56f61849840c9de10c314f0b4
7
- data.tar.gz: 5c800763646cf4d5d8d3005bf625a505390b5078fb5d84e498736d04125bfb8a3b8deff20217f8752f6f96c430c9210287e611dfe784c97d0487f9e9c56ac524
6
+ metadata.gz: c7f90eaaf33614356284717ecef4798fa50bbd6af3c927adf431c57c8ec7b14bacbe311da85f0e79ae3cbfccd048297510b9ed02fa572928cf28171c6b4f9e6a
7
+ data.tar.gz: 27cec036c8888d0d6a6fa3b8146bd724b5bada72fd226d24b4c236f1eb082b5540aa60f04fca483bdd96fd3f1d83191bd185c61a9e86d1b9cae26cd88566bd9b
@@ -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.configuration.logger.info(
12
- "POSTing #{options} to #{path}"
13
- )
14
- connection.post(path, options).body
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.configuration.content_type
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
@@ -1,3 +1,3 @@
1
1
  module Consumerable
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
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.1.1
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-18 00:00:00.000000000 Z
11
+ date: 2013-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel