bungie_client 0.5.1 → 0.6.0

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: dc038e9e7db89da4bc464558b118b0c785d18d5d
4
- data.tar.gz: 866a96de93d42311aab27f587522eb699c8b42b6
3
+ metadata.gz: 9f0b5c103d49481ce7300bd2724679f860977880
4
+ data.tar.gz: 998c54fc103ba3ccec2473bb9e6e53f747293781
5
5
  SHA512:
6
- metadata.gz: 8bad9c39faa772b5529dc523397247074c390073b6a1e6a0b3a0671a53abeb198f198ca61f252078070679af8f0fac55b513a53003135ab4613c7da772985068
7
- data.tar.gz: aa254286fab902b20ca6736cecb4a4a8792e79b1e1209ebc820b784e957290cb788c621246fe093025cef3867012b36273fbc7d8e1295a9e8dba8fc700870027
6
+ metadata.gz: 9f3f1ef5947d8e36f9109d7c9aa86a2bae01ffa84b2432e16c64f063b4821b246fa8cefe97a09495f25a0f81ddce9b74854b222b0bb95ae1c93778263a10f6aa
7
+ data.tar.gz: 270f89f6c368a7dc9f756329fc8ba3f6d7dde138d2036e5cedabf65bc53851bb343d6f1c9bb40b93bf52f49c2c7f21da65c712431a0981420bd8cc5e00de827a
@@ -21,5 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.12"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "hashie", "~> 3.4"
24
25
  spec.add_development_dependency 'mechanize', "~> 2.7", ">= 2.7.0"
25
26
  end
data/lib/bungie_client.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "json"
2
+ require "hashie"
2
3
  require "mechanize"
3
4
 
4
5
  require "bungie_client/version"
@@ -117,21 +117,25 @@ class BungieClient::Client
117
117
  # @option options [Boolean] :cache_none - disable response caching
118
118
  # @option options [Boolean] :cache_rewrite - update cache value
119
119
  # @option options [Integer] :cache_ttl - special cache ttl
120
+ # @option options [Boolean] :cache_only - allow get result only from cache
120
121
  #
121
- # @return [Array|Hash|nil]
122
+ # @return [Hash|nil]
122
123
  def get_response(uri, parameters = {}, options = {})
123
124
  if allow_get_cache options
124
125
  result = @cache.get "#{uri}+#{parameters}"
125
126
 
126
127
  return result unless result.nil?
127
128
  end
129
+ return nil if options[:cache_only]
128
130
 
129
131
  result = get uri, parameters
130
132
 
131
133
  if !result.nil? && result != ''
132
134
  result = JSON.parse result
133
135
 
134
- if !result['Response'].nil? && !result['ErrorCode'].nil? && result['ErrorCode'] == 1
136
+ if result.is_a?(Hash) && !result['Response'].nil? && result['ErrorCode'] == 1
137
+ result = Hashie::Mash.new result
138
+
135
139
  @cache.set "#{uri}+#{parameters}", result['Response'], options[:cache_ttl] if allow_set_cache options
136
140
 
137
141
  result['Response']
@@ -149,6 +153,26 @@ class BungieClient::Client
149
153
  @agent.post(self.class.request_uri(uri), query, headers).body rescue nil
150
154
  end
151
155
 
156
+ # Get Response field after post request to bungie
157
+ #
158
+ # @param [String] uri
159
+ # @param [Hash] query for post
160
+ #
161
+ # @return [Hash|nil]
162
+ def post_response(uri, query = {})
163
+ result = post uri, query
164
+
165
+ if !result.nil? && result != ''
166
+ result = JSON.parse result
167
+
168
+ if result.is_a?(Hash) && !result['Response'].nil? && result['ErrorCode'] == 1
169
+ result = Hashie::Mash.new result
170
+
171
+ result['Response']
172
+ end
173
+ end
174
+ end
175
+
152
176
  protected
153
177
 
154
178
  # Headers for requests
@@ -1,3 +1,3 @@
1
1
  module BungieClient
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bungie_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Ruban
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hashie
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: mechanize
57
71
  requirement: !ruby/object:Gem::Requirement