ringcentral_sdk 0.1.4 → 0.2.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: 04c144d9ef786c8473335c8b873781710226b6e1
4
- data.tar.gz: dc92d1eb5545de304856d4cf1d26a09ef4d56cc5
3
+ metadata.gz: b70ade50a441762f3e16344e6c7012505bf90091
4
+ data.tar.gz: 79b9a35b3726573276a1bc3fcbde970592e72399
5
5
  SHA512:
6
- metadata.gz: ac6630b7c503c5331077af606f2dd79b2879b8312a7587fead18da645daad460861eaed3b08836789832625654dab041cba70413d23ac210923c883514bf2549
7
- data.tar.gz: 8ebc499d0de3211863ff2ec46fa7a4d2b03351e761e7f004b4a5d407c876f3fc3ad7e032d8d66720b10ad7139edfc918ca85b63b73faf4b4d84320e88fb7a0c5
6
+ metadata.gz: 979970f4904d46bbb97e79bfa6cc2059ed4a82415078b8277c21d0361bfb1998f1a3ae52085db35ef23e4a94c7cb7a7b25ca52c57d9d0a37dfa361ae73100431
7
+ data.tar.gz: 70804c31f8c0ede3dc3369d3aac266669d6a8b9d8751fa6d31381d984b7e0846e43ee44f3258515732266c30df7da4a971e7c9324ad4233f683fa6d7335fdae1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  CHANGELOG
2
2
  ---------
3
+ - **2015-09-14**: 0.2.0
4
+ - Refactor platform class to remove `authorized` method in favor of `set_token`
5
+ - Add `User-Agent` header support
6
+ - Add `RingCentralSdk::VERSION`
7
+ - Update `README.md` to include token reuse
3
8
  - **2015-09-14**: 0.1.4
4
9
  - Add OAuth2 token reuse support
5
10
  - **2015-08-29**: 0.1.3
data/README.md CHANGED
@@ -122,6 +122,30 @@ platform.authorize("myUsername", nil, "myPassword")
122
122
  platform.authorize("myUsername", "myExtension", "myPassword")
123
123
  ```
124
124
 
125
+ #### Authentication Lifecycle
126
+
127
+ The platform class performs token refresh procedure automatically if needed. To save the access and refresh tokens between instances of the SDK, you can save and reuse the token as follows:
128
+
129
+ ```ruby
130
+ # Retrieve and save access token when program is to be stopped:
131
+
132
+ token_hash = sdk.platform.token.to_hash
133
+ ```
134
+
135
+ After you have saved the token hash, e.g. as JSON, you can reload it in another instance of the SDK as follows:
136
+
137
+ ```ruby
138
+ # Reuse token_hash in new SDK instance
139
+ rcsdk = RingCentralSdk::Sdk.new(
140
+ "myAppKey",
141
+ "myAppSecret",
142
+ RingCentralSdk::Sdk::RC_SERVER_SANDBOX
143
+ )
144
+ sdk2.platform.set_token(token_hash)
145
+ ```
146
+
147
+ Important! You have to manually maintain synchronization of SDK's between requests if you share authentication. When two simultaneous requests will perform refresh, only one will succeed. One of the solutions would be to have semaphor and pause other pending requests while one of them is performing refresh.
148
+
125
149
  See [the authorization docs](http://ringcentral-sdk-ruby.readthedocs.org/en/latest/usage/authorization/Authorization/) for more info including token reuse.
126
150
 
127
151
  ### API Requests
@@ -189,6 +213,12 @@ response = client.post do |req|
189
213
  end
190
214
  ```
191
215
 
216
+ ## Versioning
217
+
218
+ This project is currently in development and the API can change. During development (Version 0.x.x), versioning a minor version change indicates backward incompatibility.
219
+
220
+ Once the project is version 1.0.0 or above, it will use [semantic versioning](http://semver.org/).
221
+
192
222
  ## Change Log
193
223
 
194
224
  See [CHANGELOG.md](CHANGELOG.md)
data/VERSION.txt CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
@@ -1,3 +1,5 @@
1
+ require 'ringcentral_sdk/version.rb'
2
+
1
3
  module RingCentralSdk
2
4
  autoload :Helpers, 'ringcentral_sdk/helpers'
3
5
  autoload :Platform, 'ringcentral_sdk/platform'
@@ -21,6 +21,7 @@ module RingCentralSdk::Platform
21
21
 
22
22
  attr_reader :client
23
23
  attr_reader :token
24
+ attr_reader :ua
24
25
 
25
26
  def initialize(app_key='', app_secret='', server_url=RingCentralSdk::Sdk::RC_SERVER_SANDBOX)
26
27
  @app_key = app_key
@@ -28,6 +29,7 @@ module RingCentralSdk::Platform
28
29
  @server_url = server_url
29
30
  @token = nil
30
31
  @client = nil
32
+ @user_agent = get_user_agent()
31
33
  end
32
34
 
33
35
  def get_api_version_url()
@@ -41,28 +43,27 @@ module RingCentralSdk::Platform
41
43
  :extension => extension,
42
44
  :headers => { 'Authorization' => 'Basic ' + get_api_key() } })
43
45
 
44
- authorized(token)
46
+ set_token(token)
45
47
  end
46
48
 
47
- def set_token(token=nil)
48
- if token.is_a?(OAuth2::AccessToken)
49
- authorized(token)
50
- elsif token.is_a?(Hash)
49
+ def set_token(token)
50
+ if token.is_a?(Hash)
51
51
  oauth2client = get_oauth2_client()
52
- oauth2token = OAuth2::AccessToken::from_hash(oauth2client, token)
53
- authorized(oauth2token)
54
- else
55
- raise "Invalid Token"
52
+ token = OAuth2::AccessToken::from_hash(oauth2client, token)
53
+ end
54
+
55
+ unless token.is_a?(OAuth2::AccessToken)
56
+ raise "Token is a OAuth2::AccessToken"
56
57
  end
57
- end
58
58
 
59
- def authorized(token=nil)
60
- @token = token
59
+ @token = token
61
60
 
62
61
  @client = Faraday.new(:url => get_api_version_url()) do |conn|
63
62
  conn.request :oauth2_refresh, @token
64
63
  conn.request :json
65
64
  conn.request :url_encoded
65
+ conn.headers['User-Agent'] = @user_agent
66
+ conn.headers['Rc-User-Agent'] = @user_agent
66
67
  conn.response :json, :content_type => 'application/json'
67
68
  conn.adapter Faraday.default_adapter
68
69
  end
@@ -95,7 +96,16 @@ module RingCentralSdk::Platform
95
96
  end
96
97
  return nil
97
98
  end
98
-
99
+
100
+ def get_user_agent()
101
+ ua = "ringcentral-sdk-ruby/#{RingCentralSdk::VERSION} %s/%s %s" % [
102
+ (RUBY_ENGINE rescue nil or "ruby"),
103
+ RUBY_VERSION,
104
+ RUBY_PLATFORM
105
+ ]
106
+ return ua.strip
107
+ end
108
+
99
109
  private :get_api_version_url
100
110
  end
101
111
  end
@@ -0,0 +1,3 @@
1
+ module RingCentralSdk
2
+ VERSION = '0.2.0'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ringcentral_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Wang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-13 00:00:00.000000000 Z
11
+ date: 2015-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -154,6 +154,7 @@ files:
154
154
  - lib/ringcentral_sdk/platform.rb
155
155
  - lib/ringcentral_sdk/platform/platform.rb
156
156
  - lib/ringcentral_sdk/sdk.rb
157
+ - lib/ringcentral_sdk/version.rb
157
158
  - test/test_setup.rb
158
159
  homepage: https://github.com/grokify/
159
160
  licenses: []