ruby-box 1.14.0 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/Gemfile +1 -1
- data/Gemfile.lock +22 -4
- data/VERSION +1 -1
- data/lib/ruby-box/session.rb +15 -14
- data/ruby-box.gemspec +8 -7
- data/spec/session_spec.rb +34 -0
- metadata +24 -23
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTkxNmFlODc1ODhiMWRhOGQwNDBjMTQ0MDg5NzhiMmYyZWM5NWExYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZGM1ZDZlY2Y1NWVhZTI4Y2IyZDE3NDgzNzA5NzlmNTBiNTk5NWM0YQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YWExMDRjYzk3MGNjMzg2MjExZjg5MmFhOGNkZTRlMWI5ZmJmNGJhMDFhMWFi
|
10
|
+
YmZiYmExNGU4OGFjYmQ2MDFkZDk3YjIyMzQyYjQxZDE1MDI3NTA3NjgzYjc5
|
11
|
+
YWM5ZjBiZGRiN2IyMTkwNjU4YTg0OWQ0ZWQzNjZlZWQ3MTliYWY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzEwNWE3ZWJjMjk2Yzc1MTQwNWU2ZDUzOTFhOTMyYTY3MmZhMDM5NzU3NDM3
|
14
|
+
YjVhZjhhMGYyMjgzMTc2ZjM4Zjc4ODdiMTljZDk0NDM0NGI3MGVkOGJlYWRk
|
15
|
+
N2FlNTI0YzIzZDA5MzdjM2IzNWQ3MDAwZDhhMGRjMWYzZTZiNGQ=
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,21 +2,37 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
addressable (2.2.8)
|
5
|
+
builder (3.2.2)
|
5
6
|
crack (0.3.1)
|
6
7
|
diff-lcs (1.1.3)
|
7
8
|
faraday (0.8.4)
|
8
9
|
multipart-post (~> 1.1)
|
9
|
-
git (1.2.
|
10
|
+
git (1.2.8)
|
11
|
+
github_api (0.10.1)
|
12
|
+
addressable
|
13
|
+
faraday (~> 0.8.1)
|
14
|
+
hashie (>= 1.2)
|
15
|
+
multi_json (~> 1.4)
|
16
|
+
nokogiri (~> 1.5.2)
|
17
|
+
oauth2
|
18
|
+
hashie (3.3.1)
|
19
|
+
highline (1.6.21)
|
10
20
|
httpauth (0.2.0)
|
11
|
-
jeweler (1.
|
21
|
+
jeweler (1.8.8)
|
22
|
+
builder
|
12
23
|
bundler (~> 1.0)
|
13
24
|
git (>= 1.2.5)
|
25
|
+
github_api (= 0.10.1)
|
26
|
+
highline (>= 1.6.15)
|
27
|
+
nokogiri (= 1.5.10)
|
14
28
|
rake
|
29
|
+
rdoc
|
15
30
|
json (1.7.7)
|
16
31
|
jwt (0.1.5)
|
17
32
|
multi_json (>= 1.0)
|
18
33
|
multi_json (1.6.0)
|
19
34
|
multipart-post (1.1.5)
|
35
|
+
nokogiri (1.5.10)
|
20
36
|
oauth2 (0.8.0)
|
21
37
|
faraday (~> 0.8)
|
22
38
|
httpauth (~> 0.1)
|
@@ -24,7 +40,9 @@ GEM
|
|
24
40
|
multi_json (~> 1.0)
|
25
41
|
rack (~> 1.2)
|
26
42
|
rack (1.4.5)
|
27
|
-
rake (
|
43
|
+
rake (10.3.2)
|
44
|
+
rdoc (4.1.2)
|
45
|
+
json (~> 1.4)
|
28
46
|
rspec (2.10.0)
|
29
47
|
rspec-core (~> 2.10.0)
|
30
48
|
rspec-expectations (~> 2.10.0)
|
@@ -43,7 +61,7 @@ PLATFORMS
|
|
43
61
|
DEPENDENCIES
|
44
62
|
addressable
|
45
63
|
bundler
|
46
|
-
jeweler
|
64
|
+
jeweler
|
47
65
|
json
|
48
66
|
multipart-post
|
49
67
|
oauth2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.15.0
|
data/lib/ruby-box/session.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'oauth2'
|
2
2
|
|
3
|
-
module RubyBox
|
3
|
+
module RubyBox
|
4
4
|
class Session
|
5
5
|
|
6
6
|
OAUTH2_URLS = {
|
@@ -8,7 +8,7 @@ module RubyBox
|
|
8
8
|
:authorize_url => "/api/oauth2/authorize",
|
9
9
|
:token_url => "/api/oauth2/token"
|
10
10
|
}
|
11
|
-
|
11
|
+
|
12
12
|
def initialize(opts={}, backoff=0.1)
|
13
13
|
|
14
14
|
@backoff = backoff # try not to excessively hammer API.
|
@@ -24,9 +24,11 @@ module RubyBox
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def authorize_url(redirect_uri)
|
28
|
-
|
29
|
-
|
27
|
+
def authorize_url(redirect_uri, state=nil)
|
28
|
+
opts = { :redirect_uri => redirect_uri }
|
29
|
+
opts[:state] = state if state
|
30
|
+
|
31
|
+
@oauth2_client.auth_code.authorize_url(opts)
|
30
32
|
end
|
31
33
|
|
32
34
|
def get_access_token(code)
|
@@ -37,7 +39,7 @@ module RubyBox
|
|
37
39
|
refresh_access_token_obj = OAuth2::AccessToken.new(@oauth2_client, @access_token.token, {'refresh_token' => refresh_token})
|
38
40
|
@access_token = refresh_access_token_obj.refresh!
|
39
41
|
end
|
40
|
-
|
42
|
+
|
41
43
|
def build_auth_header
|
42
44
|
"BoxAuth api_key=#{@api_key}&auth_token=#{@auth_token}"
|
43
45
|
end
|
@@ -53,21 +55,20 @@ module RubyBox
|
|
53
55
|
request = Net::HTTP::Delete.new( uri.request_uri )
|
54
56
|
resp = request( uri, request, raw )
|
55
57
|
end
|
56
|
-
|
58
|
+
|
57
59
|
def request(uri, request, raw=false, retries=0)
|
58
60
|
|
59
61
|
http = Net::HTTP.new(uri.host, uri.port)
|
60
62
|
http.use_ssl = true
|
61
|
-
http.ssl_version = :SSLv3
|
62
63
|
#http.set_debug_output($stdout)
|
63
|
-
|
64
|
+
|
64
65
|
if @access_token
|
65
66
|
request.add_field('Authorization', "Bearer #{@access_token.token}")
|
66
67
|
else
|
67
68
|
request.add_field('Authorization', build_auth_header)
|
68
69
|
end
|
69
70
|
|
70
|
-
|
71
|
+
|
71
72
|
request.add_field('As-User', "#{@as_user}") if @as_user
|
72
73
|
|
73
74
|
response = http.request(request)
|
@@ -90,7 +91,7 @@ module RubyBox
|
|
90
91
|
def do_stream(url, opts)
|
91
92
|
params = {
|
92
93
|
:content_length_proc => opts[:content_length_proc],
|
93
|
-
:progress_proc => opts[:progress_proc]
|
94
|
+
:progress_proc => opts[:progress_proc]
|
94
95
|
}
|
95
96
|
|
96
97
|
if @access_token
|
@@ -98,12 +99,12 @@ module RubyBox
|
|
98
99
|
else
|
99
100
|
params['Authorization'] = build_auth_header
|
100
101
|
end
|
101
|
-
|
102
|
+
|
102
103
|
params['As-User'] = @as_user if @as_user
|
103
104
|
|
104
105
|
open(url, params)
|
105
106
|
end
|
106
|
-
|
107
|
+
|
107
108
|
def handle_errors( response, raw )
|
108
109
|
status = response.code.to_i
|
109
110
|
body = response.body
|
@@ -121,7 +122,7 @@ module RubyBox
|
|
121
122
|
case status / 100
|
122
123
|
when 3
|
123
124
|
# 302 Found. We should return the url
|
124
|
-
parsed_body["location"] = response["Location"] if status == 302
|
125
|
+
parsed_body["location"] = response["Location"] if status == 302
|
125
126
|
when 4
|
126
127
|
raise(RubyBox::ItemNameInUse.new(parsed_body, status, body), parsed_body["message"]) if parsed_body["code"] == "item_name_in_use"
|
127
128
|
raise(RubyBox::AuthError.new(parsed_body, status, body), parsed_body["message"]) if parsed_body["code"] == "unauthorized" || status == 401
|
data/ruby-box.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: ruby-box 1.
|
5
|
+
# stub: ruby-box 1.15.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "ruby-box"
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.15.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Attachments.me"]
|
14
|
-
s.date = "2014-
|
14
|
+
s.date = "2014-10-16"
|
15
15
|
s.description = "ruby gem for box.com 2.0 api"
|
16
16
|
s.email = "ben@attachments.me"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -56,12 +56,13 @@ Gem::Specification.new do |s|
|
|
56
56
|
"spec/integration_spec.rb",
|
57
57
|
"spec/item_spec.rb",
|
58
58
|
"spec/me_spec.rb",
|
59
|
+
"spec/session_spec.rb",
|
59
60
|
"spec/spec_helper.rb",
|
60
61
|
"spec/users_spec.rb"
|
61
62
|
]
|
62
63
|
s.homepage = "http://github.com/attachmentsme/ruby-box"
|
63
64
|
s.licenses = ["MIT"]
|
64
|
-
s.rubygems_version = "2.2.
|
65
|
+
s.rubygems_version = "2.2.2"
|
65
66
|
s.summary = "ruby gem for box.com 2.0 api"
|
66
67
|
|
67
68
|
if s.respond_to? :specification_version then
|
@@ -74,7 +75,7 @@ Gem::Specification.new do |s|
|
|
74
75
|
s.add_runtime_dependency(%q<addressable>, [">= 0"])
|
75
76
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
76
77
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
77
|
-
s.add_development_dependency(%q<jeweler>, ["
|
78
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
78
79
|
s.add_development_dependency(%q<webmock>, [">= 0"])
|
79
80
|
else
|
80
81
|
s.add_dependency(%q<multipart-post>, [">= 0"])
|
@@ -83,7 +84,7 @@ Gem::Specification.new do |s|
|
|
83
84
|
s.add_dependency(%q<addressable>, [">= 0"])
|
84
85
|
s.add_dependency(%q<rspec>, [">= 0"])
|
85
86
|
s.add_dependency(%q<bundler>, [">= 0"])
|
86
|
-
s.add_dependency(%q<jeweler>, ["
|
87
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
87
88
|
s.add_dependency(%q<webmock>, [">= 0"])
|
88
89
|
end
|
89
90
|
else
|
@@ -93,7 +94,7 @@ Gem::Specification.new do |s|
|
|
93
94
|
s.add_dependency(%q<addressable>, [">= 0"])
|
94
95
|
s.add_dependency(%q<rspec>, [">= 0"])
|
95
96
|
s.add_dependency(%q<bundler>, [">= 0"])
|
96
|
-
s.add_dependency(%q<jeweler>, ["
|
97
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
97
98
|
s.add_dependency(%q<webmock>, [">= 0"])
|
98
99
|
end
|
99
100
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'ruby-box'
|
5
|
+
|
6
|
+
describe RubyBox::Session do
|
7
|
+
before do
|
8
|
+
@auth_code = double("OAuth2::Strategy::AuthCode")
|
9
|
+
@client = double("OAuth2::Client")
|
10
|
+
|
11
|
+
@client.stub(:auth_code) { @auth_code }
|
12
|
+
OAuth2::Client.stub(:new) { @client }
|
13
|
+
|
14
|
+
@session = RubyBox::Session.new({
|
15
|
+
client_id: "client id",
|
16
|
+
client_secret: "client secret"
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:redirect_uri) { "redirect_uri" }
|
21
|
+
let(:state) { "state" }
|
22
|
+
|
23
|
+
describe '#authorize_url' do
|
24
|
+
it "should accept redirect_uri" do
|
25
|
+
@auth_code.should_receive(:authorize_url).with({ redirect_uri: redirect_uri})
|
26
|
+
@session.authorize_url(redirect_uri)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should accept redirect_uri and state" do
|
30
|
+
@auth_code.should_receive(:authorize_url).with({ redirect_uri: redirect_uri, state: state})
|
31
|
+
@session.authorize_url(redirect_uri, state)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,125 +1,125 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-box
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Attachments.me
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - '>='
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - '>='
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: oauth2
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - '>='
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - '>='
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: json
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - '>='
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - '>='
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: addressable
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - '>='
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - '>='
|
66
|
+
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - '>='
|
73
|
+
- - ! '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - '>='
|
80
|
+
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: bundler
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - '>='
|
87
|
+
- - ! '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - '>='
|
94
|
+
- - ! '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: jeweler
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ! '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ! '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: webmock
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - '>='
|
115
|
+
- - ! '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - '>='
|
122
|
+
- - ! '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
description: ruby gem for box.com 2.0 api
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- spec/integration_spec.rb
|
168
168
|
- spec/item_spec.rb
|
169
169
|
- spec/me_spec.rb
|
170
|
+
- spec/session_spec.rb
|
170
171
|
- spec/spec_helper.rb
|
171
172
|
- spec/users_spec.rb
|
172
173
|
homepage: http://github.com/attachmentsme/ruby-box
|
@@ -179,17 +180,17 @@ require_paths:
|
|
179
180
|
- lib
|
180
181
|
required_ruby_version: !ruby/object:Gem::Requirement
|
181
182
|
requirements:
|
182
|
-
- - '>='
|
183
|
+
- - ! '>='
|
183
184
|
- !ruby/object:Gem::Version
|
184
185
|
version: '0'
|
185
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
187
|
requirements:
|
187
|
-
- - '>='
|
188
|
+
- - ! '>='
|
188
189
|
- !ruby/object:Gem::Version
|
189
190
|
version: '0'
|
190
191
|
requirements: []
|
191
192
|
rubyforge_project:
|
192
|
-
rubygems_version: 2.2.
|
193
|
+
rubygems_version: 2.2.2
|
193
194
|
signing_key:
|
194
195
|
specification_version: 4
|
195
196
|
summary: ruby gem for box.com 2.0 api
|