bcx 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -7
- data/docs/docco.css +10 -4
- data/docs/{bcx.html → lib/bcx.html} +37 -22
- data/docs/{http.html → lib/bcx/client/http.html} +32 -22
- data/docs/{oauth.html → lib/bcx/client/oauth.html} +33 -23
- data/docs/{configuration.html → lib/bcx/configuration.html} +7 -7
- data/docs/lib/bcx/launchpad/oauth.html +137 -0
- data/docs/{access.html → lib/bcx/resources/access.html} +31 -21
- data/docs/lib/bcx/resources/authorization.html +140 -0
- data/docs/{person.html → lib/bcx/resources/person.html} +31 -21
- data/docs/{project.html → lib/bcx/resources/project.html} +32 -22
- data/docs/{todo.html → lib/bcx/resources/todo.html} +33 -23
- data/docs/{todolist.html → lib/bcx/resources/todolist.html} +34 -24
- data/docs/{response_error.html → lib/bcx/response_error.html} +14 -14
- data/docs/{version.html → lib/bcx/version.html} +5 -5
- data/docs/public/fonts/aller-bold.eot +0 -0
- data/docs/public/fonts/aller-bold.ttf +0 -0
- data/docs/public/fonts/aller-bold.woff +0 -0
- data/docs/public/fonts/aller-light.eot +0 -0
- data/docs/public/fonts/aller-light.ttf +0 -0
- data/docs/public/fonts/aller-light.woff +0 -0
- data/docs/public/fonts/novecento-bold.eot +0 -0
- data/docs/public/fonts/novecento-bold.ttf +0 -0
- data/docs/public/fonts/novecento-bold.woff +0 -0
- data/lib/bcx.rb +5 -0
- data/lib/bcx/client/oauth.rb +1 -1
- data/lib/bcx/launchpad/oauth.rb +22 -0
- data/lib/bcx/resources/authorization.rb +16 -0
- data/lib/bcx/version.rb +1 -1
- data/spec/bcx/authorization_spec.rb +13 -0
- data/spec/bcx/launchpad_spec.rb +16 -0
- data/spec/cassettes/Bcx_Resources_Authorization/GET_/authorization/first_account_should_have_the_correct_id.yml +52 -0
- metadata +34 -25
- data/docs/collection.html +0 -103
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/bcx.rb
CHANGED
@@ -15,6 +15,7 @@ module Bcx
|
|
15
15
|
autoload :Project, 'bcx/resources/project'
|
16
16
|
autoload :Person, 'bcx/resources/person'
|
17
17
|
autoload :Access, 'bcx/resources/access'
|
18
|
+
autoload :Authorization, 'bcx/resources/authorization'
|
18
19
|
end
|
19
20
|
|
20
21
|
module Client
|
@@ -22,6 +23,10 @@ module Bcx
|
|
22
23
|
autoload :OAuth, 'bcx/client/oauth'
|
23
24
|
end
|
24
25
|
|
26
|
+
module Launchpad
|
27
|
+
autoload :OAuth, 'bcx/launchpad/oauth'
|
28
|
+
end
|
29
|
+
|
25
30
|
class << self
|
26
31
|
attr_accessor :configuration
|
27
32
|
end
|
data/lib/bcx/client/oauth.rb
CHANGED
@@ -21,7 +21,7 @@ module Bcx
|
|
21
21
|
resource :people, class_name: 'Bcx::Resources::Person'
|
22
22
|
|
23
23
|
def initialize(options = {})
|
24
|
-
@account = Bcx.configuration.account
|
24
|
+
@account = options[:account] || Bcx.configuration.account
|
25
25
|
@api_version = Bcx.configuration.api_version
|
26
26
|
|
27
27
|
options[:site] = "https://basecamp.com/#{@account}/api/#{@api_version}"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Bcx
|
2
|
+
module Launchpad
|
3
|
+
class OAuth < Rapidash::Client
|
4
|
+
method :oauth
|
5
|
+
|
6
|
+
extension :json
|
7
|
+
encode_request_with :json
|
8
|
+
|
9
|
+
raise_errors
|
10
|
+
|
11
|
+
resource :authorization, class_name: "Bcx::Resources::Authorization"
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
options[:site] ||= "https://launchpad.37signals.com"
|
15
|
+
options[:uid] ||= options[:client_id]
|
16
|
+
options[:secret] ||= options[:client_secret]
|
17
|
+
|
18
|
+
super(options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Bcx
|
2
|
+
module Resources
|
3
|
+
|
4
|
+
# Bcx::Resources::Authorization
|
5
|
+
# Provides access to the authorization resource
|
6
|
+
#
|
7
|
+
# Fetch authorization
|
8
|
+
# GET /authorization.json
|
9
|
+
#
|
10
|
+
# launchpad.authorization!
|
11
|
+
#
|
12
|
+
class Authorization < Rapidash::Base
|
13
|
+
url :authorization
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/bcx/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bcx::Resources::Authorization, :vcr do
|
4
|
+
let(:launchpad) { Bcx::Launchpad::OAuth.new(client_id: '748cc9c949af86f2e3fb35564f7e209b1d2c27d2', client_secret: '7fba79ec3bf1eb9e278098031414e5a3a41ec842', access_token: 'BAhbByIBsHsiZXhwaXJlc19hdCI6IjIwMTMtMDktMTNUMTI6NDk6MzBaIiwidXNlcl9pZHMiOlsxNzE3NDMwNV0sImNsaWVudF9pZCI6Ijc0OGNjOWM5NDlhZjg2ZjJlM2ZiMzU1NjRmN2UyMDliMWQyYzI3ZDIiLCJ2ZXJzaW9uIjoxLCJhcGlfZGVhZGJvbHQiOiJmZmE1OTgzMzQ3YTY2MWExM2Y1YWE3YTM0ODVhYzk4YiJ9dToJVGltZQ2sYRzA05PlxQ==--e995b8e9cb3cc37b7f4f90d967bb23d889145384') }
|
5
|
+
|
6
|
+
describe "GET /authorization" do
|
7
|
+
let(:authorization) { launchpad.authorization! }
|
8
|
+
|
9
|
+
it "first account should have the correct id" do
|
10
|
+
expect(authorization.accounts.first.id).to eq 2274488
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bcx::Launchpad do
|
4
|
+
context "oauth" do
|
5
|
+
let(:launchpad) { Bcx::Launchpad::OAuth.new(client_id: '748cc9c949af86f2e3fb35564f7e209b1d2c27d2', client_secret: '7fba79ec3bf1eb9e278098031414e5a3a41ec842', access_token: 'BAhbByIBsHsiZXhwaXJlc19hdCI6IjIwMTMtMDktMTNUMTI6NDk6MzBaIiwidXNlcl9pZHMiOlsxNzE3NDMwNV0sImNsaWVudF9pZCI6Ijc0OGNjOWM5NDlhZjg2ZjJlM2ZiMzU1NjRmN2UyMDliMWQyYzI3ZDIiLCJ2ZXJzaW9uIjoxLCJhcGlfZGVhZGJvbHQiOiJmZmE1OTgzMzQ3YTY2MWExM2Y1YWE3YTM0ODVhYzk4YiJ9dToJVGltZQ2sYRzA05PlxQ==--e995b8e9cb3cc37b7f4f90d967bb23d889145384') }
|
6
|
+
|
7
|
+
it "should assign credentials" do
|
8
|
+
expect(launchpad.uid).to eq '748cc9c949af86f2e3fb35564f7e209b1d2c27d2'
|
9
|
+
expect(launchpad.secret).to eq '7fba79ec3bf1eb9e278098031414e5a3a41ec842'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should provide an access token" do
|
13
|
+
expect(launchpad.access_token).not_to be_nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://launchpad.37signals.com/authorization.json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.8.8
|
12
|
+
content-type:
|
13
|
+
- application/json
|
14
|
+
Authorization:
|
15
|
+
- Bearer BAhbByIBsHsiZXhwaXJlc19hdCI6IjIwMTMtMDktMTNUMTI6NDk6MzBaIiwidXNlcl9pZHMiOlsxNzE3NDMwNV0sImNsaWVudF9pZCI6Ijc0OGNjOWM5NDlhZjg2ZjJlM2ZiMzU1NjRmN2UyMDliMWQyYzI3ZDIiLCJ2ZXJzaW9uIjoxLCJhcGlfZGVhZGJvbHQiOiJmZmE1OTgzMzQ3YTY2MWExM2Y1YWE3YTM0ODVhYzk4YiJ9dToJVGltZQ2sYRzA05PlxQ==--e995b8e9cb3cc37b7f4f90d967bb23d889145384
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message:
|
20
|
+
headers:
|
21
|
+
server:
|
22
|
+
- nginx
|
23
|
+
date:
|
24
|
+
- Fri, 30 Aug 2013 12:54:58 GMT
|
25
|
+
content-type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
transfer-encoding:
|
28
|
+
- chunked
|
29
|
+
connection:
|
30
|
+
- close
|
31
|
+
status:
|
32
|
+
- 200 OK
|
33
|
+
etag:
|
34
|
+
- ! '"08fb7932a74cfd43967d40c6b26b68d4"'
|
35
|
+
x-frame-options:
|
36
|
+
- SAMEORIGIN
|
37
|
+
x-ua-compatible:
|
38
|
+
- IE=Edge,chrome=1
|
39
|
+
x-runtime:
|
40
|
+
- '0.007646'
|
41
|
+
x-request-id:
|
42
|
+
- 4553850ce04a7ecfe50aeb802b895220
|
43
|
+
cache-control:
|
44
|
+
- max-age=0, private, must-revalidate
|
45
|
+
strict-transport-security:
|
46
|
+
- max-age=31536000
|
47
|
+
body:
|
48
|
+
encoding: US-ASCII
|
49
|
+
string: ! '{"accounts":[{"name":"Paul Springett''s Basecamp","href":"https://basecamp.com/2274488/api/v1","id":2274488,"product":"bcx"}],"identity":{"id":6967737,"last_name":"Springett","email_address":"paul@springett.me","first_name":"Paul"},"expires_at":"2013-09-13T12:49:30Z"}'
|
50
|
+
http_version:
|
51
|
+
recorded_at: Fri, 30 Aug 2013 12:55:00 GMT
|
52
|
+
recorded_with: VCR 2.5.0
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Springett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rapidash
|
@@ -28,56 +28,56 @@ dependencies:
|
|
28
28
|
name: rake
|
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: :development
|
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: rspec
|
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: :development
|
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: simplecov
|
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: :development
|
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: vcr
|
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
|
description: Fully-fledged Ruby API wrapper for Basecamp Next
|
@@ -95,15 +95,20 @@ files:
|
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
97
|
- bcx.gemspec
|
98
|
-
- docs/access.html
|
99
|
-
- docs/bcx.html
|
100
|
-
- docs/collection.html
|
101
|
-
- docs/configuration.html
|
102
98
|
- docs/docco.css
|
103
|
-
- docs/
|
104
|
-
- docs/
|
105
|
-
- docs/
|
106
|
-
- docs/
|
99
|
+
- docs/lib/bcx.html
|
100
|
+
- docs/lib/bcx/client/http.html
|
101
|
+
- docs/lib/bcx/client/oauth.html
|
102
|
+
- docs/lib/bcx/configuration.html
|
103
|
+
- docs/lib/bcx/launchpad/oauth.html
|
104
|
+
- docs/lib/bcx/resources/access.html
|
105
|
+
- docs/lib/bcx/resources/authorization.html
|
106
|
+
- docs/lib/bcx/resources/person.html
|
107
|
+
- docs/lib/bcx/resources/project.html
|
108
|
+
- docs/lib/bcx/resources/todo.html
|
109
|
+
- docs/lib/bcx/resources/todolist.html
|
110
|
+
- docs/lib/bcx/response_error.html
|
111
|
+
- docs/lib/bcx/version.html
|
107
112
|
- docs/public/fonts/aller-bold.eot
|
108
113
|
- docs/public/fonts/aller-bold.ttf
|
109
114
|
- docs/public/fonts/aller-bold.woff
|
@@ -114,15 +119,13 @@ files:
|
|
114
119
|
- docs/public/fonts/novecento-bold.ttf
|
115
120
|
- docs/public/fonts/novecento-bold.woff
|
116
121
|
- docs/public/stylesheets/normalize.css
|
117
|
-
- docs/response_error.html
|
118
|
-
- docs/todo.html
|
119
|
-
- docs/todolist.html
|
120
|
-
- docs/version.html
|
121
122
|
- lib/bcx.rb
|
122
123
|
- lib/bcx/client/http.rb
|
123
124
|
- lib/bcx/client/oauth.rb
|
124
125
|
- lib/bcx/configuration.rb
|
126
|
+
- lib/bcx/launchpad/oauth.rb
|
125
127
|
- lib/bcx/resources/access.rb
|
128
|
+
- lib/bcx/resources/authorization.rb
|
126
129
|
- lib/bcx/resources/person.rb
|
127
130
|
- lib/bcx/resources/project.rb
|
128
131
|
- lib/bcx/resources/todo.rb
|
@@ -131,7 +134,9 @@ files:
|
|
131
134
|
- lib/bcx/version.rb
|
132
135
|
- lib/tasks/docs.rake
|
133
136
|
- spec/bcx/access_spec.rb
|
137
|
+
- spec/bcx/authorization_spec.rb
|
134
138
|
- spec/bcx/client_spec.rb
|
139
|
+
- spec/bcx/launchpad_spec.rb
|
135
140
|
- spec/bcx/person_spec.rb
|
136
141
|
- spec/bcx/project_spec.rb
|
137
142
|
- spec/bcx/todo_spec.rb
|
@@ -141,6 +146,7 @@ files:
|
|
141
146
|
- spec/cassettes/Bcx_Resources_Access/GET_/projects/2951531/accesses_json/first_access_should_have_the_correct_id.yml
|
142
147
|
- spec/cassettes/Bcx_Resources_Access/GET_/projects/2951531/accesses_json/should_be_an_array.yml
|
143
148
|
- spec/cassettes/Bcx_Resources_Access/POST_/projects/2951531/accesses_json/should_grant_access.yml
|
149
|
+
- spec/cassettes/Bcx_Resources_Authorization/GET_/authorization/first_account_should_have_the_correct_id.yml
|
144
150
|
- spec/cassettes/Bcx_Resources_Person/DELETE_/people/4904728_json/should_delete_a_todolist.yml
|
145
151
|
- spec/cassettes/Bcx_Resources_Person/GET_/people/4666033_json/should_have_the_correct_id.yml
|
146
152
|
- spec/cassettes/Bcx_Resources_Person/GET_/people/4666033_json/should_return_a_hash.yml
|
@@ -191,24 +197,26 @@ require_paths:
|
|
191
197
|
- lib
|
192
198
|
required_ruby_version: !ruby/object:Gem::Requirement
|
193
199
|
requirements:
|
194
|
-
- - '>='
|
200
|
+
- - ! '>='
|
195
201
|
- !ruby/object:Gem::Version
|
196
202
|
version: '0'
|
197
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
204
|
requirements:
|
199
|
-
- - '>='
|
205
|
+
- - ! '>='
|
200
206
|
- !ruby/object:Gem::Version
|
201
207
|
version: '0'
|
202
208
|
requirements: []
|
203
209
|
rubyforge_project:
|
204
|
-
rubygems_version: 2.0.
|
210
|
+
rubygems_version: 2.0.5
|
205
211
|
signing_key:
|
206
212
|
specification_version: 4
|
207
213
|
summary: Fully-fledged Ruby API wrapper for Basecamp Next. Uses the Rapidash gem under
|
208
214
|
the hood.
|
209
215
|
test_files:
|
210
216
|
- spec/bcx/access_spec.rb
|
217
|
+
- spec/bcx/authorization_spec.rb
|
211
218
|
- spec/bcx/client_spec.rb
|
219
|
+
- spec/bcx/launchpad_spec.rb
|
212
220
|
- spec/bcx/person_spec.rb
|
213
221
|
- spec/bcx/project_spec.rb
|
214
222
|
- spec/bcx/todo_spec.rb
|
@@ -218,6 +226,7 @@ test_files:
|
|
218
226
|
- spec/cassettes/Bcx_Resources_Access/GET_/projects/2951531/accesses_json/first_access_should_have_the_correct_id.yml
|
219
227
|
- spec/cassettes/Bcx_Resources_Access/GET_/projects/2951531/accesses_json/should_be_an_array.yml
|
220
228
|
- spec/cassettes/Bcx_Resources_Access/POST_/projects/2951531/accesses_json/should_grant_access.yml
|
229
|
+
- spec/cassettes/Bcx_Resources_Authorization/GET_/authorization/first_account_should_have_the_correct_id.yml
|
221
230
|
- spec/cassettes/Bcx_Resources_Person/DELETE_/people/4904728_json/should_delete_a_todolist.yml
|
222
231
|
- spec/cassettes/Bcx_Resources_Person/GET_/people/4666033_json/should_have_the_correct_id.yml
|
223
232
|
- spec/cassettes/Bcx_Resources_Person/GET_/people/4666033_json/should_return_a_hash.yml
|
data/docs/collection.html
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
|
3
|
-
<html>
|
4
|
-
<head>
|
5
|
-
<title>collection.rb</title>
|
6
|
-
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
7
|
-
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
8
|
-
<link rel="stylesheet" media="all" href="docco.css" />
|
9
|
-
</head>
|
10
|
-
<body>
|
11
|
-
<div id="container">
|
12
|
-
<div id="background"></div>
|
13
|
-
|
14
|
-
<ul id="jump_to">
|
15
|
-
<li>
|
16
|
-
<a class="large" href="javascript:void(0);">Jump To …</a>
|
17
|
-
<a class="small" href="javascript:void(0);">+</a>
|
18
|
-
<div id="jump_wrapper">
|
19
|
-
<div id="jump_page">
|
20
|
-
|
21
|
-
|
22
|
-
<a class="source" href="configuration.html">
|
23
|
-
configuration.rb
|
24
|
-
</a>
|
25
|
-
|
26
|
-
|
27
|
-
<a class="source" href="response_error.html">
|
28
|
-
response_error.rb
|
29
|
-
</a>
|
30
|
-
|
31
|
-
|
32
|
-
<a class="source" href="version.html">
|
33
|
-
version.rb
|
34
|
-
</a>
|
35
|
-
|
36
|
-
|
37
|
-
<a class="source" href="collection.html">
|
38
|
-
collection.rb
|
39
|
-
</a>
|
40
|
-
|
41
|
-
</div>
|
42
|
-
</li>
|
43
|
-
</ul>
|
44
|
-
|
45
|
-
<ul class="sections">
|
46
|
-
|
47
|
-
<li id="title">
|
48
|
-
<div class="annotation">
|
49
|
-
<h1>collection.rb</h1>
|
50
|
-
</div>
|
51
|
-
</li>
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
<li id="section-1">
|
56
|
-
<div class="annotation">
|
57
|
-
|
58
|
-
<div class="pilwrap ">
|
59
|
-
<a class="pilcrow" href="#section-1">¶</a>
|
60
|
-
</div>
|
61
|
-
|
62
|
-
</div>
|
63
|
-
|
64
|
-
<div class="content"><div class='highlight'><pre><span class="class"><span class="keyword">module</span> <span class="title">Rapidash</span></span>
|
65
|
-
<span class="class"><span class="keyword">module</span> <span class="title">Collection</span></span>
|
66
|
-
|
67
|
-
<span class="function"><span class="keyword">def</span> <span class="title"><span class="keyword">self</span></span>.<span class="title">included</span><span class="params">(base)</span></span>
|
68
|
-
base.extend <span class="constant">ClassMethods</span>
|
69
|
-
<span class="keyword">end</span>
|
70
|
-
|
71
|
-
<span class="class"><span class="keyword">module</span> <span class="title">ClassMethods</span></span>
|
72
|
-
<span class="function"><span class="keyword">def</span> <span class="title">collection</span><span class="params">(name, attrs = {})</span></span>
|
73
|
-
path = attrs[<span class="symbol">:path</span>] || name.to_s
|
74
|
-
path.gsub!(<span class="regexp">/^\//</span>, <span class="string">''</span>)
|
75
|
-
|
76
|
-
method = attrs[<span class="symbol">:method</span>] || <span class="symbol">:get</span>
|
77
|
-
|
78
|
-
define_method(<span class="string">"<span class="subst">#{name}</span>!"</span>) <span class="keyword">do</span>
|
79
|
-
original_url = <span class="variable">@url</span>
|
80
|
-
|
81
|
-
<span class="variable">@url</span> += <span class="string">"/<span class="subst">#{path}</span>"</span>
|
82
|
-
<span class="variable">@options</span>[<span class="symbol">:method</span>] = method
|
83
|
-
result = call!
|
84
|
-
|
85
|
-
<span class="variable">@url</span> = original_url
|
86
|
-
|
87
|
-
result
|
88
|
-
<span class="keyword">end</span>
|
89
|
-
<span class="keyword">end</span>
|
90
|
-
<span class="keyword">end</span>
|
91
|
-
<span class="keyword">end</span>
|
92
|
-
<span class="keyword">end</span>
|
93
|
-
|
94
|
-
<span class="class"><span class="keyword">class</span> <span class="title">Rapidash::Base</span></span>
|
95
|
-
<span class="keyword">include</span> <span class="constant">Rapidash::Collection</span>
|
96
|
-
<span class="keyword">end</span></pre></div></div>
|
97
|
-
|
98
|
-
</li>
|
99
|
-
|
100
|
-
</ul>
|
101
|
-
</div>
|
102
|
-
</body>
|
103
|
-
</html>
|