rdstation-ruby-client 0.1 → 0.1.1

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: 8d8b49b1c3af26dff4944b5a246306050577424f
4
- data.tar.gz: 3e4238d351ee0b2820370d4c7b9ea8285f565fd6
3
+ metadata.gz: 49d611a1dd83c95db29c6fd6abaf5e174d0cfaab
4
+ data.tar.gz: 47644e5e101c69feeacd833935dae34764a915e5
5
5
  SHA512:
6
- metadata.gz: 14804ae659e189e1ac5f1d3880e8fe7071a1dcbdb035a237e12b06b5f7ee9113d067eb86b28fb63fe47c2dc76cd499e64b7b74bf36d1e0393ff960b892fdee91
7
- data.tar.gz: 2fbd0fbe9a184a30b592747d5dcc79b4714c187b993428a69526d1f3a16f0918726ef4abd3fea21fcba23484aef92e23360ed6ab39e19817858751000a76fa1f
6
+ metadata.gz: f9d6ddc90bab5f0ba6a9403a10f4cd6efad29f31c2998f2ea1cbac80996caf1e97bcccc6c59a27a3723c311ba505b7f4fef3f45685fe7fd1d99115b64736731f
7
+ data.tar.gz: 628b0e48df49f7082784d6a84e4d6a31590237f9140198bed8206d7e1a12c545f87dfcb0512f418af785735b10719fee8f4736391ad4ffebdf6a5c2d5827b975
data/README.md CHANGED
@@ -47,6 +47,33 @@ rdstation_client = RDStation::Client.new('rdstation_token', 'auth_token')
47
47
  rdstation_client.change_lead_status(email: 'joe@foo.bar', status: 'won', value: 999)
48
48
  ```
49
49
 
50
+ ### Authentication
51
+
52
+ #### Getting authentication URL
53
+
54
+ ```ruby
55
+ rdstation_authentication = RDStation::Authentication.new('client_id', 'client_secret')
56
+
57
+ redirect_url = 'https://yourapp.org/auth/callback'
58
+ rdstation_authentication.auth_url(redirect_url)
59
+ ```
60
+
61
+ #### Getting access_token
62
+
63
+ You will need the code param that is returned from RD Station to your application after the user confirms the access at the authorization dialog.
64
+
65
+ ```ruby
66
+ rdstation_authentication = RDStation::Authentication.new('client_id', 'client_secret')
67
+ rdstation_authentication.authenticate(code_returned_from_rdstation)
68
+ ```
69
+
70
+ #### Updating access_token
71
+
72
+ ```ruby
73
+ rdstation_authentication = RDStation::Authentication.new('client_id', 'client_secret')
74
+ rdstation_authentication.update_access_token('refresh_token')
75
+ ```
76
+
50
77
  ### Contacts
51
78
 
52
79
  #### Getting a Contact by UUID
@@ -1,3 +1,4 @@
1
1
  require "httparty"
2
2
  require "rdstation/client"
3
3
  require "rdstation/contacts"
4
+ require "rdstation/authentication"
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ module RDStation
3
+ class Authentication
4
+ include HTTParty
5
+
6
+ def initialize(client_id, client_secret)
7
+ @client_id = client_id
8
+ @client_secret = client_secret
9
+ end
10
+
11
+ #
12
+ # param redirect_url
13
+ # URL that the user will be redirected
14
+ # after confirming application authorization
15
+ #
16
+ def auth_url(redirect_url)
17
+ "https://api.rd.services/auth/dialog?client_id=#{@client_id}&redirect_url=#{redirect_url}"
18
+ end
19
+
20
+ #
21
+ # param code
22
+ # parameter sent by RDStation after user confirms authorization
23
+ #
24
+ def authenticate(code)
25
+ post_to_auth_endpoint({ :code => code })
26
+ end
27
+
28
+ #
29
+ # param refresh_token
30
+ # parameter sent by RDStation after authenticate
31
+ #
32
+ def update_access_token(refresh_token)
33
+ post_to_auth_endpoint({ :refresh_token => refresh_token })
34
+ end
35
+
36
+ private
37
+
38
+ def auth_token_url
39
+ "https://api.rd.services/auth/token"
40
+ end
41
+
42
+ def post_to_auth_endpoint(params)
43
+ default_body = { :client_id => @client_id, :client_secret => @client_secret }
44
+
45
+ self.class.post(
46
+ auth_token_url,
47
+ :headers => {
48
+ "Accept-Encoding": "identity"
49
+ },
50
+ :body => default_body.merge(params)
51
+ )
52
+ end
53
+ end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module RDStation
2
- VERSION = '0.1'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdstation-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo L F Casaretto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-03 00:00:00.000000000 Z
11
+ date: 2018-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,7 @@ files:
122
122
  - README.md
123
123
  - Rakefile
124
124
  - lib/rdstation-ruby-client.rb
125
+ - lib/rdstation/authentication.rb
125
126
  - lib/rdstation/client.rb
126
127
  - lib/rdstation/contacts.rb
127
128
  - lib/rdstation/version.rb