Skip to content

Commit

Permalink
faraday_middleware json
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlong committed May 25, 2018
1 parent 0220c61 commit 6abb0ac
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -4,6 +4,7 @@ gem 'addressable'
gem 'concurrent-ruby'
gem 'pubnub'
gem 'faraday'
gem 'faraday_middleware'

group :test do
gem 'dotenv'
Expand Down
5 changes: 4 additions & 1 deletion Gemfile.lock
Expand Up @@ -59,6 +59,8 @@ GEM
dry-types (~> 0.12.0)
faraday (0.14.0)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0)
hitimes (1.2.6)
httpclient (2.8.3)
inflecto (0.0.2)
Expand Down Expand Up @@ -104,9 +106,10 @@ DEPENDENCIES
coveralls
dotenv
faraday
faraday_middleware
pubnub
rspec
simplecov

BUNDLED WITH
1.13.6
1.16.1
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -38,7 +38,7 @@ rc.authorize(username: ENV['RINGCENTRAL_USERNAME'], extension: ENV['RINGCENTRAL_
# get
r = rc.get('/restapi/v1.0/account/~/extension/~')
expect(r).not_to be_nil
expect('101').to eq(JSON.parse(r.body)['extensionNumber'])
expect('101').to eq(r.body['extensionNumber'])
```


Expand Down
6 changes: 4 additions & 2 deletions lib/ringcentral.rb
Expand Up @@ -3,6 +3,7 @@
require 'json'
require 'concurrent'
require 'faraday'
require 'faraday_middleware'
require 'tmpdir'

class RingCentral
Expand All @@ -27,6 +28,7 @@ def initialize(client_id, client_secret, server)
@faraday = Faraday.new(url: server) do |faraday|
faraday.request :multipart
faraday.request :url_encoded
faraday.response :json, :content_type => /\bjson$/
faraday.adapter Faraday.default_adapter
end
end
Expand Down Expand Up @@ -60,7 +62,7 @@ def authorize(username: nil, extension: nil, password: nil, auth_code: nil, redi
end
self.token = nil
r = self.post('/restapi/oauth/token', payload: payload)
self.token = JSON.parse(r.body)
self.token = r.body
end

def refresh
Expand All @@ -71,7 +73,7 @@ def refresh
}
self.token = nil
r = self.post('/restapi/oauth/token', payload: payload)
self.token = JSON.parse(r.body)
self.token = r.body
end

def revoke
Expand Down
4 changes: 2 additions & 2 deletions lib/subscription.rb
Expand Up @@ -47,7 +47,7 @@ def subscription=(value)

def subscribe
r = @rc.post('/restapi/v1.0/subscription', payload: request_body)
self.subscription = JSON.parse(r.body)
self.subscription = r.body
@pubnub = Pubnub.new(subscribe_key: @subscription['deliveryMode']['subscriberKey'])
@pubnub.add_listener(name: 'default', callback: @callback)
@pubnub.subscribe(channels: @subscription['deliveryMode']['address'])
Expand All @@ -56,7 +56,7 @@ def subscribe
def refresh
return if @subscription == nil
r = @rc.put("/restapi/v1.0/subscription/#{@subscription['id']}", payload: request_body)
self.subscription = JSON.parse(r.body)
self.subscription = r.body
end

def revoke
Expand Down
3 changes: 2 additions & 1 deletion ringcentral-sdk.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |gem|
gem.name = 'ringcentral-sdk'
gem.version = '0.8.2'
gem.version = '0.9.0'
gem.authors = ['Tyler Liu']
gem.email = ['tyler.liu@ringcentral.com']
gem.description = 'Ruby SDK for you to access RingCentral platform API.'
Expand All @@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
gem.add_dependency('concurrent-ruby', '~> 1.0', '>= 1.0.2')
gem.add_dependency('pubnub', '~> 4.0', '>= 4.0.27')
gem.add_dependency('faraday', '~> 0.10', '>= 0.10.0')
gem.add_dependency('faraday_middleware', '~> 0.12', '>= 0.12.2')
end
2 changes: 1 addition & 1 deletion spec/fax_spec.rb
Expand Up @@ -15,7 +15,7 @@
]
)
expect(r).not_to be_nil
message = JSON.parse(r.body)
message = r.body
expect('Fax').to eq(message['type'])
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/mms_spec.rb
Expand Up @@ -19,7 +19,7 @@
]
)
expect(r).not_to be_nil
message = JSON.parse(r.body)
message = r.body
expect('SMS').to eq(message['type'])
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/ringcentral_spec.rb
Expand Up @@ -46,7 +46,7 @@
# get
r = rc.get('/restapi/v1.0/account/~/extension/~')
expect(r).not_to be_nil
expect('101').to eq(JSON.parse(r.body)['extensionNumber'])
expect('101').to eq(r.body['extensionNumber'])

# post
r = rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
Expand All @@ -55,18 +55,18 @@
text: 'Hello world'
})
expect(r).not_to be_nil
message = JSON.parse(r.body)
message = r.body
expect('SMS').to eq(message['type'])
messageUrl = "/restapi/v1.0/account/~/extension/~/message-store/#{message['id']}"

# put
r = rc.put(messageUrl, payload: { readStatus: 'Unread' })
expect(r).not_to be_nil
message = JSON.parse(r.body)
message = r.body
expect('Unread').to eq(message['readStatus'])
r = rc.put(messageUrl, payload: { readStatus: 'Read' })
expect(r).not_to be_nil
message = JSON.parse(r.body)
message = r.body
expect('Read').to eq(message['readStatus'])

# todo: test patch
Expand All @@ -76,7 +76,7 @@
expect(r).not_to be_nil
r = rc.get(messageUrl)
expect(r).not_to be_nil
message = JSON.parse(r.body)
message = r.body
expect('Deleted').to eq(message['availability'])
end
end
Expand Down

0 comments on commit 6abb0ac

Please sign in to comment.