goplay-publisher-sdk 0.0.909 → 0.0.911

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDU5Zjg5NDJlMTE4ZjkxMTdhOWMwMGM5NjNmOTcxODZkZGEzM2IxZg==
4
+ YmU5ZjYzNDhlZGUzMWRmOWI3ZjM1ZTk2MzM3ZTE3ZTFhYTBjOWY1MA==
5
5
  data.tar.gz: !binary |-
6
- YzljMjFjOWZiY2ZiN2U0Mjk0NDFjNzM4Y2E3ODlkZmMzN2I4YTZlZA==
6
+ YWE3MjM3MzRkYmExNGQxMDc2M2YyNTM1NmYzN2EzZWYyNjQwNzAyYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MWNhZmU1YWRiNmUyMGU0ZTYyNmY2MGUyYWNhZDYwNDQ0OTViM2RkYWUyOGUy
10
- MTkxYjRhNjdiZmYwNzBjZGQ2MDJiOGY3N2ZhZDI1N2ZhYmQyODBkNWRhYjY5
11
- YjE1MDczZmUxODllYjg0MDk5MmFjNDAwOGE2YjY3MGMzZDRhNWY=
9
+ YzBlZDRhYzhlZDU1MjViODE4NGYyMWJkYWFjOWQ3NTQ3ZTJiZDk3YjBkNDBi
10
+ OTAxODBkYzQ1MzYyY2FmMzdkMjQ2ZDY2NjExYjk3NGI3ZTM5OWE1ZjI3Mzg1
11
+ ZGVkODZjNGYwNGQ1NDlmMGQ3YTYzM2Y0ZDIzYTMwYmJkZDFjY2E=
12
12
  data.tar.gz: !binary |-
13
- NGFlN2U5N2FlODhjNzUzNDU0YWY0ZmVlOWVjYzRlZWZkZTlmMmIzZTk1MDYz
14
- ZmQ1YzJhNjBmZGI3NmRjZjNkOGNkNTQ2NWM0ZTM2ZGExNjVjZDg1YjhkNzI0
15
- MTVhYTZmMjY5MzliM2U0NGI3ZWViOGUwOWUxNDFiMGMyYTc4ZTc=
13
+ MmI0ZWY1YzFhMDVmMTJmMTE3NDA0YTU0MmFmZDc0ODMxM2NkZGZhOTRlNzll
14
+ OTk2MTE3NjQzZTMzNmIwNzM0ODY3NmUzNjczYTI0NjQ2NDVlNzI0ZjY2YWI0
15
+ NmFkY2Q1N2NhNWVmYjJkN2U3MjlhYTA4NmFiZGM2NTJiM2Y3MDI=
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright 2013 Playgistics, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+ not use this file except in compliance with the License. You may obtain
5
+ a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ License for the specific language governing permissions and limitations
13
+ under the License.
14
+
@@ -0,0 +1,3 @@
1
+ == PublisherSDK
2
+
3
+ You should document your project here.
@@ -1 +1 @@
1
- require_relative './publisher_sdk.rb'
1
+ require_relative './publisher_sdk.rb'
@@ -2,6 +2,7 @@ require_relative 'sdk_component.rb'
2
2
  require 'json'
3
3
  require 'cacert'
4
4
  require 'net/https'
5
+ require 'version'
5
6
 
6
7
  module SDKHost
7
8
  attr_accessor 'test'
@@ -22,7 +23,7 @@ module SDKHost
22
23
  end
23
24
 
24
25
  class GraphRequest < SDKComponent
25
- attr_accessor 'effective_url','test'
26
+ attr_accessor 'effective_url','test', 'params'
26
27
 
27
28
  def initialize endpoint=nil, params={}, method='get'
28
29
  @endpoint = self.ensure_slash endpoint
@@ -35,7 +36,6 @@ class GraphRequest < SDKComponent
35
36
  @params[:method] = @method
36
37
  end
37
38
 
38
-
39
39
  def get_response
40
40
  result = self.run
41
41
  if result[0]=="{" || result[0] == "["
@@ -46,8 +46,6 @@ class GraphRequest < SDKComponent
46
46
  GraphResponse.new _data, self
47
47
  end
48
48
 
49
-
50
-
51
49
  def run
52
50
  params = self.clean_params(@params)
53
51
  url = self.make_uri SDKHost::current_host
@@ -55,6 +53,7 @@ class GraphRequest < SDKComponent
55
53
  client.use_ssl = true
56
54
  client.ca_file = Cacert.pem
57
55
  req = Net::HTTP::Post.new @endpoint
56
+ req.add_field 'User-Agent', 'goplay-ruby-'+GoplayPublisherSDK::VERSION
58
57
  req.set_form_data params
59
58
  response = client.start {|http| http.request(req) }
60
59
  @effective_url = make_uri(SDKHost::current_host, @endpoint, params).to_s
@@ -24,7 +24,7 @@ class GraphResponse < SDKComponent
24
24
  @data = response["data"]
25
25
  end
26
26
  if !response["error"].nil?
27
- @error = SDKException.new "Exception from "+request.effective_url+": "+response["error"]["message"]
27
+ @error = SDKException.new "Exception from "+request.effective_url+": "+response["error"]["message"],response["error"]["code"]
28
28
  end
29
29
  @paging = response["paging"]
30
30
  end
@@ -3,6 +3,7 @@ require_relative 'graph_response'
3
3
  require 'digest/md5'
4
4
  class PublisherSDK < SDKComponent
5
5
  attr_accessor :endpoint, :token
6
+ ALLOWED_FAILURES = 2
6
7
  @@token_cache = {}
7
8
  def initialize pub_id, secret, is_test = false
8
9
  @pub_id = pub_id.to_s
@@ -25,24 +26,32 @@ class PublisherSDK < SDKComponent
25
26
  def extend_endpoint endpoint
26
27
  result = PublisherSDK.new @pub_id,@secret
27
28
  result.endpoint = @endpoint + self.ensure_slash(endpoint)
28
- result.token = get_stored_token;
29
29
  result
30
30
  end
31
31
 
32
32
  def get_token
33
33
  if !self.get_stored_token
34
- @@token_cache[@cache_key] = {:token => self.get_token_from_server, :failures => 0}
34
+ self.get_token_from_server
35
35
  end
36
36
  return get_stored_token
37
37
  end
38
38
 
39
+ def set_stored_token token, failures = 0
40
+ @@token_cache[@cache_key] = {:token => token, :failures => failures}
41
+ end
42
+
39
43
  def get_stored_token
40
- return @@token_cache[@cache_key] ? @@token_cache[@cache_key][:token] : nil
44
+ return self.get_stored_token_object[:token]
45
+ end
46
+
47
+ def get_stored_token_object
48
+ return @@token_cache[@cache_key] ? @@token_cache[@cache_key] : {:token => nil, :failures => 0}
41
49
  end
42
50
 
43
51
  def get_token_from_server
44
52
  req = GraphRequest.new 'oauth/access_token', {:client_id => @pub_id, :client_secret=>@secret, :grant_type=> 'publisher_credentials'}
45
- req.get_response.response["access_token"]
53
+ set_stored_token req.get_response.response['access_token']
54
+ get_stored_token
46
55
  end
47
56
 
48
57
  def get arg1=nil, arg2=nil
@@ -73,14 +82,46 @@ class PublisherSDK < SDKComponent
73
82
  params[:access_token] = self.get_token
74
83
  endpoint = @endpoint
75
84
  @endpoint = ""
76
- resp = self.handle_response(GraphRequest.new(endpoint, params, method).get_response)
85
+ self.handle_response(GraphRequest.new(endpoint, params, method).get_response)
77
86
  end
78
87
 
79
88
  def handle_response response
80
89
  if !response.error.nil?
81
- raise response.error
90
+ if response.error.code==190
91
+ return self.retry_request_with_new_token response
92
+ else
93
+ self.clear_token_failures
94
+ raise response.error
95
+ end
96
+ end
97
+ self.clear_token_failures
98
+ response
99
+ end
100
+
101
+ def fail_token
102
+ t = self.get_stored_token_object
103
+ self.set_stored_token t[:token], t[:failures]+1
104
+ end
105
+
106
+ def clear_token_failures
107
+ self.set_stored_token self.get_stored_token
108
+ end
109
+
110
+ def get_token_failures
111
+ t = self.get_stored_token_object
112
+ t[:failures]
113
+ end
114
+
115
+ def retry_request_with_new_token resp
116
+ self.fail_token
117
+ if self.get_token_failures <= PublisherSDK::ALLOWED_FAILURES
118
+ req = resp.request
119
+ req.params[:access_token] = self.get_token_from_server
120
+ return self.handle_response req.get_response
82
121
  end
83
- return response
122
+ raise resp.error
84
123
  end
124
+
125
+
85
126
 
86
127
  end
@@ -1,5 +1,5 @@
1
1
  class SDKComponent
2
-
2
+
3
3
  def ensure_slash s
4
4
  s = s.to_s
5
5
  if s.empty?
@@ -1,3 +1,8 @@
1
1
  class SDKException < Exception
2
-
2
+ attr_accessor 'code'
3
+
4
+ def initialize message, code
5
+ @message = message
6
+ @code = code
7
+ end
3
8
  end
@@ -0,0 +1,8 @@
1
+ module GoplayPublisherSDK
2
+ VERSION_NUMBERS = [
3
+ VERSION_MAJOR = 0,
4
+ VERSION_MINOR = 0,
5
+ VERSION_BUILD = 911,
6
+ ]
7
+ VERSION = VERSION_NUMBERS.join(".")
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goplay-publisher-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.909
4
+ version: 0.0.911
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Nordstrom
@@ -30,12 +30,15 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
+ - lib/goplay-publisher-sdk.rb
33
34
  - lib/graph_request.rb
34
35
  - lib/graph_response.rb
35
- - lib/sdk_component.rb
36
36
  - lib/publisher_sdk.rb
37
+ - lib/sdk_component.rb
37
38
  - lib/sdk_exception.rb
38
- - lib/goplay-publisher-sdk.rb
39
+ - lib/version.rb
40
+ - LICENSE
41
+ - README.md
39
42
  homepage: http://rubygems.org/gems/publisher-sdk
40
43
  licenses: []
41
44
  metadata: {}