plangrade-ruby 0.3.23 → 0.3.24

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: ecb0949e0cc91058f9f73270572ec1430024c60e
4
- data.tar.gz: aed964c431dcfc9b084351fe17d7ce0567f51c73
3
+ metadata.gz: 84042f01be72b4e9a4f175176cdd38ca0f93ff82
4
+ data.tar.gz: 3666e185380752fb2780dca13905ad3f6e5b2d94
5
5
  SHA512:
6
- metadata.gz: cd5fbc422ed5ad109cbf3e7fc807c26e100a9fffdc700efcf64616e357397804957d6dd2bdba69bce8bbd47f0ff0eab15fad84136f499a83bc5c4bc745890ac3
7
- data.tar.gz: 9640f6b24614b22ba86792672a8239aa47cb78e92285a761ec18f1301bf569d568a1f21cb2cf037565e4f97e6d5117e8479a07c2ce13fff98a0a3600921f01ce
6
+ metadata.gz: e0b23cff9db342711a11b81a4171d3e4a7321321d8d9a2af6735f1f3c4d9229a7378d5840b29e182c8dbe524fb43549b2e1504a17d4e9932779f9b0ec2f68aa2
7
+ data.tar.gz: 1c89eef0bf1516cc388e4bf4257b419a96fc7a4e1f1bd25189d36c5f488d2026e95990c20dbb272eeea2b56f7f17d815938d094dd1936de6b1594535c338a514
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -53,14 +53,14 @@ require 'plangrade'
53
53
 
54
54
  # Begin by getting the authorization url
55
55
  plangrade_client = Plangrade::OAuth2Client.new(ENV['PLANGRADE_CLIENT_ID'], ENV['PLANGRADE_CLIENT_SECRET'])
56
- auth_url = plangrade_client.webserver_authorization_url(your_redirect_uri)
56
+ auth_url = plangrade_client.webserver_authorization_url(:redirect_uri => 'your_redirect_uri')
57
57
  ```
58
58
 
59
59
  After the user follows the link created above and authorizes your app, they will be redirected to your `redirect_uri`, with a code in the params that you can use to obtain an access token.
60
60
 
61
61
  ```ruby
62
62
  plangrade_client = Plangrade::OAuth2Client.new(ENV['PLANGRADE_CLIENT_ID'], ENV['PLANGRADE_CLIENT_SECRET'])
63
- response = plangrade_client.exchange_auth_code_for_token(params[:code], your_redirect_uri)
63
+ response = plangrade_client.exchange_auth_code_for_token(:params => {:code => params[:code], :redirect_uri => 'your_redirect_uri'})
64
64
  token = JSON.parse response.body
65
65
  access_token = token["access_token"]
66
66
  refresh_token = token["refresh_token"]
@@ -75,7 +75,7 @@ This gem also allows you to use a `refresh_token` to obtain a new `access_token`
75
75
  ```ruby
76
76
  # Set up a plangrade OAuth2 client and retrieve your refresh_token
77
77
  plangrade_client = Plangrade::OAuth2Client.new(ENV['PLANGRADE_CLIENT_ID'], ENV['PLANGRADE_CLIENT_SECRET'])
78
- response = plangrade_client.refresh_access_token(your_refresh_token, your_redirect_uri)
78
+ response = plangrade_client.refresh_access_token(:params => {:refresh_token => 'your_refresh_token', :redirect_uri => 'http://localhost:3000/callback'})
79
79
  token = JSON.parse response.body
80
80
  access_token = token["access_token"]
81
81
  refresh_token = token["refresh_token"]
@@ -30,8 +30,8 @@ module Plangrade
30
30
  # >> https://plangrade.com/oauth/authorize/?client_id={client_id}&
31
31
  # redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fplangrade%2Fcallback&response_type=code
32
32
  #
33
- def webserver_authorization_url(redirect)
34
- opts = {:redirect_uri => redirect}
33
+ def webserver_authorization_url(opts={})
34
+ opts[:scope] = normalize_scope(opts[:scope]) if opts[:scope]
35
35
  authorization_code.authorization_url(opts)
36
36
  end
37
37
 
@@ -54,9 +54,12 @@ module Plangrade
54
54
 
55
55
  # client_id={client_id}&code=G3Y6jU3a&grant_type=authorization_code&
56
56
  # redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fplangrade%2Fcallback&client_secret={client_secret}
57
- def exchange_auth_code_for_token(code, redirect)
58
- opts = {:params => {:redirect_uri => redirect}}
59
- opts[:authenticate] = :body
57
+ def exchange_auth_code_for_token(opts={})
58
+ unless (opts[:params] && opts[:params][:code])
59
+ raise ArgumentError.new("You must include an authorization code as a parameter")
60
+ end
61
+ opts[:authenticate] ||= :body
62
+ code = opts[:params].delete(:code)
60
63
  authorization_code.get_token(code, opts)
61
64
  end
62
65
 
@@ -78,10 +81,13 @@ module Plangrade
78
81
 
79
82
  # client_id={client_id}&refresh_token=G3Y6jU3a&grant_type=refresh_token&
80
83
  # client_secret={client_secret}
81
- def refresh_access_token(ref_token, redirect)
82
- opts = {:params => {:redirect_uri => redirect}}
84
+ def refresh_access_token(opts={})
85
+ unless (opts[:params] && opts[:params][:refresh_token])
86
+ raise ArgumentError.new("You must provide a refresh_token as a parameter")
87
+ end
83
88
  opts[:authenticate] = :body
84
- refresh_token.get_token(ref_token, opts)
89
+ token = opts[:params].delete(:refresh_token)
90
+ refresh_token.get_token(token, opts)
85
91
  end
86
92
  end
87
93
  end
@@ -1,5 +1,5 @@
1
1
  module Plangrade
2
2
  module Ruby
3
- VERSION = "0.3.23"
3
+ VERSION = "0.3.24"
4
4
  end
5
5
  end
@@ -38,9 +38,14 @@ describe Plangrade::OAuth2Client do
38
38
  "client_id" => "PRbTcg9qjgKsp4jjpm1pw",
39
39
  "redirect_uri" => "https://localhost:3000/callback",
40
40
  "response_type" =>"code",
41
+ "state" => "12345"
41
42
  }
42
43
 
43
- auth_url = subject.webserver_authorization_url('https://localhost:3000/callback')
44
+ auth_url = subject.webserver_authorization_url(
45
+ :client_id => 'PRbTcg9qjgKsp4jjpm1pw',
46
+ :state => '12345',
47
+ :redirect_uri => 'https://localhost:3000/callback'
48
+ )
44
49
 
45
50
  parsed_url = Addressable::URI.parse(auth_url)
46
51
  expect(parsed_url.path).to eq '/oauth/authorize'
@@ -67,7 +72,12 @@ describe Plangrade::OAuth2Client do
67
72
  'User-Agent' =>"Plangrade OAuth2 Client #{Plangrade::Ruby::VERSION}"
68
73
  })
69
74
 
70
- subject.exchange_auth_code_for_token('MmOGL795LbIZuJJVnL49Cc', 'http://localhost:3000/callback')
75
+ subject.exchange_auth_code_for_token(
76
+ :params => {
77
+ :code => 'MmOGL795LbIZuJJVnL49Cc',
78
+ :redirect_uri => 'http://localhost:3000/callback'
79
+ }
80
+ )
71
81
  end
72
82
  end
73
83
 
@@ -88,7 +98,12 @@ describe Plangrade::OAuth2Client do
88
98
  'User-Agent' =>"Plangrade OAuth2 Client #{Plangrade::Ruby::VERSION}"
89
99
  })
90
100
 
91
- subject.refresh_access_token('MmOGL795LbIZuJJVnL49Cc', 'http://localhost:3000/callback')
101
+ subject.refresh_access_token(
102
+ :params => {
103
+ :refresh_token => 'MmOGL795LbIZuJJVnL49Cc',
104
+ :redirect_uri => 'http://localhost:3000/callback'
105
+ }
106
+ )
92
107
  end
93
108
  end
94
109
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plangrade-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.23
4
+ version: 0.3.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Reynoso
metadata.gz.sig CHANGED
Binary file