printreleaf 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 486b2cb5c05b402a052003a10bc002bf87fbaf52
4
- data.tar.gz: 10d5cf04397909af9b2728aae27ca10b6db3ad4c
3
+ metadata.gz: f8493e94acd1e6a129764c830e31111088ecdde7
4
+ data.tar.gz: 7f2919d25338b5d908e957d21a161eef3907ab35
5
5
  SHA512:
6
- metadata.gz: 4228e9b32e587d3436ce0d0b96c639a9fa16a97d0666d3d5e15ccef4a817637431c807c53fbf1ecd50156eba95b7289acf6266e229ac19fad3c7948243d1394b
7
- data.tar.gz: d0010720154d6d3b0275d00cd15fdc0f400a960d3bd58c7e7887f63b8b87a3104ac4fd5a216be3c90b336e17524b7ffce474fc81a486a7eb76c0a21bf13f4c32
6
+ metadata.gz: ce220e933e0b3acc6b2109bfc69278582800170d21d3206a03d7063149fb88e617fb0200c6c1f48006863b3be447c3652aea0e75142b42d71d8410dcbcb9e9dc
7
+ data.tar.gz: c9ff6bde14c21eabc7c62db359916cfca3681fa5a6ed453d6e40b08bcf81fcac167e88cbd7ba712b800ad7ec74f1df6b4b14c3863a392795af53fbe2fcd4a7ce
@@ -4,6 +4,7 @@ module PrintReleaf
4
4
 
5
5
  ENDPOINT = "api.printreleaf.com/v1/"
6
6
  PROTOCOL = "https"
7
+ USER_AGENT = "PrintReleaf Ruby/#{PrintReleaf::VERSION}"
7
8
  MAX_RETRY_COUNT = 2
8
9
  RETRY_DELAY_BASE = 1.5 # Base for exponential delay
9
10
 
@@ -27,6 +28,7 @@ module PrintReleaf
27
28
  attr_writer :api_key
28
29
  attr_writer :endpoint
29
30
  attr_writer :protocol
31
+ attr_writer :user_agent
30
32
  attr_accessor :logger
31
33
 
32
34
  def api_key
@@ -45,6 +47,10 @@ module PrintReleaf
45
47
  @protocol || PROTOCOL
46
48
  end
47
49
 
50
+ def user_agent
51
+ @user_agent || USER_AGENT
52
+ end
53
+
48
54
  def get(uri="/", params={})
49
55
  request :get, uri, params
50
56
  end
@@ -64,18 +70,30 @@ module PrintReleaf
64
70
  def request(verb, uri, params={})
65
71
  perform_request do
66
72
  uri = Util.join_uri(endpoint, uri)
67
- url = "#{protocol}://#{api_key}:@#{uri}"
73
+ url = "#{protocol}://#{uri}"
74
+
75
+ request_params = {
76
+ method: verb,
77
+ url: url,
78
+ headers: {
79
+ accept: :json,
80
+ :Authorization => "Bearer #{api_key}",
81
+ :user_agent => user_agent
82
+ }
83
+ }
84
+
85
+ if verb == :get || verb == :delete
86
+ request_params[:headers][:params] = params unless params.empty?
87
+ else
88
+ request_params[:payload] = params.to_json
89
+ request_params[:headers][:content_type] = :json
90
+ end
68
91
 
69
92
  unless logger.nil?
70
93
  logger.info "[PrintReleaf] #{verb.upcase} #{uri}"
71
94
  end
72
95
 
73
- response = case verb
74
- when :get; RestClient.get url, params: params, accept: :json
75
- when :post; RestClient.post url, params.to_json, accept: :json, content_type: :json
76
- when :patch; RestClient.patch url, params.to_json, accept: :json, content_type: :json
77
- when :delete; RestClient.delete url
78
- end
96
+ response = RestClient::Request.execute(request_params)
79
97
 
80
98
  JSON.parse(response.body)
81
99
  end
@@ -1,3 +1,3 @@
1
1
  module PrintReleaf
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: printreleaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Casey O'Hara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-07 00:00:00.000000000 Z
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie