bcx 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +6 -0
- data/README.md +57 -4
- data/docs/bcx.html +171 -0
- data/docs/configuration.html +128 -0
- data/docs/docco.css +500 -0
- data/docs/http.html +125 -0
- data/docs/oauth.html +127 -0
- data/docs/person.html +125 -0
- data/docs/project.html +143 -0
- 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/fleurons.eot +0 -0
- data/docs/public/fonts/fleurons.ttf +0 -0
- data/docs/public/fonts/fleurons.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/docs/public/images/gray.png +0 -0
- data/docs/public/stylesheets/normalize.css +375 -0
- data/docs/response_error.html +117 -0
- data/docs/todo.html +138 -0
- data/docs/todolist.html +148 -0
- data/docs/version.html +103 -0
- data/lib/bcx/client/http.rb +25 -0
- data/lib/bcx/client/oauth.rb +27 -0
- data/lib/bcx/resources/person.rb +30 -7
- data/lib/bcx/resources/project.rb +7 -10
- data/lib/bcx/resources/todolist.rb +11 -4
- data/lib/bcx/version.rb +1 -1
- data/lib/bcx.rb +12 -1
- data/spec/bcx/client_spec.rb +24 -19
- data/spec/bcx/person_spec.rb +55 -0
- data/spec/bcx/project_spec.rb +1 -1
- data/spec/bcx/todo_spec.rb +43 -0
- data/spec/bcx/todolist_spec.rb +19 -3
- data/spec/cassettes/Bcx_Client/error_handling/should_raise_exception.yml +56 -0
- data/spec/cassettes/Bcx_Resources_Person/DELETE_/people/4904728_json/should_delete_a_todolist.yml +101 -0
- data/spec/cassettes/Bcx_Resources_Person/GET_/people/4666033_json/should_have_the_correct_id.yml +58 -0
- data/spec/cassettes/Bcx_Resources_Person/GET_/people/4666033_json/should_return_a_hash.yml +58 -0
- data/spec/cassettes/Bcx_Resources_Person/GET_/people/me_json/should_have_assigned_todos.yml +58 -0
- data/spec/cassettes/Bcx_Resources_Person/GET_/people/me_json/should_have_the_correct_id.yml +58 -0
- data/spec/cassettes/Bcx_Resources_Person/GET_/people/me_json/should_return_a_hash.yml +58 -0
- data/spec/cassettes/Bcx_Resources_Person/GET_/people_json/first_person_should_have_the_correct_id.yml +56 -0
- data/spec/cassettes/Bcx_Resources_Person/GET_/people_json/should_be_an_array.yml +56 -0
- data/spec/cassettes/Bcx_Resources_Todo/DELETE_/projects/2951531/todos/48545200_json/should_delete_the_given_todo.yml +101 -0
- data/spec/cassettes/Bcx_Resources_Todo/GET_/projects/2951531/todos/48545200_json/should_have_the_correct_id.yml +61 -0
- data/spec/cassettes/Bcx_Resources_Todo/GET_/projects/2951531/todos/48545200_json/should_return_a_hash.yml +61 -0
- data/spec/cassettes/Bcx_Resources_Todo/POST_/projects/2951531/todolists/2951531/todos_json/should_create_a_new_todo.yml +56 -0
- data/spec/cassettes/Bcx_Resources_Todo/POST_/projects/2951531/todolists/8268819/todos_json/should_create_a_new_todo.yml +62 -0
- data/spec/cassettes/Bcx_Resources_Todo/PUT_/projects/2951531/todos/48545200_json/should_update_an_existing_todo.yml +61 -0
- data/spec/cassettes/Bcx_Resources_Todolist/DELETE_/projects/2956584/todolists/8268819_json/should_create_a_new_todolist.yml +66 -0
- data/spec/cassettes/Bcx_Resources_Todolist/DELETE_/projects/2956584/todolists/8268819_json/should_delete_a_todolist.yml +101 -0
- data/spec/cassettes/Bcx_Resources_Todolist/POST_/projects/123/todolists_json/should_create_a_new_todolist.yml +62 -0
- data/spec/cassettes/Bcx_Resources_Todolist/PUT_/projects/2956584/todolists/8268819_json/should_create_a_new_todolist.yml +186 -0
- metadata +88 -14
- data/lib/bcx/client.rb +0 -24
data/docs/todolist.html
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<title>todolist.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="bcx.html">
|
23
|
+
bcx.rb
|
24
|
+
</a>
|
25
|
+
|
26
|
+
|
27
|
+
<a class="source" href="http.html">
|
28
|
+
http.rb
|
29
|
+
</a>
|
30
|
+
|
31
|
+
|
32
|
+
<a class="source" href="oauth.html">
|
33
|
+
oauth.rb
|
34
|
+
</a>
|
35
|
+
|
36
|
+
|
37
|
+
<a class="source" href="configuration.html">
|
38
|
+
configuration.rb
|
39
|
+
</a>
|
40
|
+
|
41
|
+
|
42
|
+
<a class="source" href="person.html">
|
43
|
+
person.rb
|
44
|
+
</a>
|
45
|
+
|
46
|
+
|
47
|
+
<a class="source" href="project.html">
|
48
|
+
project.rb
|
49
|
+
</a>
|
50
|
+
|
51
|
+
|
52
|
+
<a class="source" href="todo.html">
|
53
|
+
todo.rb
|
54
|
+
</a>
|
55
|
+
|
56
|
+
|
57
|
+
<a class="source" href="todolist.html">
|
58
|
+
todolist.rb
|
59
|
+
</a>
|
60
|
+
|
61
|
+
|
62
|
+
<a class="source" href="response_error.html">
|
63
|
+
response_error.rb
|
64
|
+
</a>
|
65
|
+
|
66
|
+
|
67
|
+
<a class="source" href="version.html">
|
68
|
+
version.rb
|
69
|
+
</a>
|
70
|
+
|
71
|
+
</div>
|
72
|
+
</li>
|
73
|
+
</ul>
|
74
|
+
|
75
|
+
<ul class="sections">
|
76
|
+
|
77
|
+
<li id="title">
|
78
|
+
<div class="annotation">
|
79
|
+
<h1>todolist.rb</h1>
|
80
|
+
</div>
|
81
|
+
</li>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
<li id="section-1">
|
86
|
+
<div class="annotation">
|
87
|
+
|
88
|
+
<div class="pilwrap ">
|
89
|
+
<a class="pilcrow" href="#section-1">¶</a>
|
90
|
+
</div>
|
91
|
+
|
92
|
+
</div>
|
93
|
+
|
94
|
+
<div class="content"><div class='highlight'><pre><span class="class"><span class="keyword">module</span> <span class="title">Bcx</span></span>
|
95
|
+
<span class="class"><span class="keyword">module</span> <span class="title">Resources</span></span></pre></div></div>
|
96
|
+
|
97
|
+
</li>
|
98
|
+
|
99
|
+
|
100
|
+
<li id="section-2">
|
101
|
+
<div class="annotation">
|
102
|
+
|
103
|
+
<div class="pilwrap ">
|
104
|
+
<a class="pilcrow" href="#section-2">¶</a>
|
105
|
+
</div>
|
106
|
+
<p>Bcx::Resources::Todolist
|
107
|
+
Provides access to todolist resoource both at the client level and per-project</p>
|
108
|
+
<p>Get all todolists for a project
|
109
|
+
GET /projects/123/todolists.json</p>
|
110
|
+
<p> client.projects(123).todolists!</p>
|
111
|
+
<p>Get all completed todolists for a project
|
112
|
+
GET /projects/1/todolists/completed.json</p>
|
113
|
+
<p> client.projects(123).todolists.completed!</p>
|
114
|
+
<p>Get todolists for all projects
|
115
|
+
GET /todolists.json</p>
|
116
|
+
<p> client.todolists!</p>
|
117
|
+
<p>Get completed todolists for all projects
|
118
|
+
GET /todolists/completed.json</p>
|
119
|
+
<p> client.todolists.completed!</p>
|
120
|
+
<p>Get specific todolist including the todos
|
121
|
+
GET /projects/123/todolists/456.json</p>
|
122
|
+
<p> client.projects(123).todolists!(456)</p>
|
123
|
+
<p>Create a new todolist
|
124
|
+
POST /projects/1/todolists.json</p>
|
125
|
+
<p> client.projects(123).todolists.create!(name: 'My todolist', description: 'This is a todolist')</p>
|
126
|
+
<p>Update an existing todolist
|
127
|
+
PUT /projects/123/todolists/456.json</p>
|
128
|
+
<p> client.projects(123).todolists(456).update!(name: 'Updated todolist')</p>
|
129
|
+
<p>Delete a todolist
|
130
|
+
DELETE /projects/123/todolists/456.json</p>
|
131
|
+
<p> client.projects(123).todolists(456).delete!</p>
|
132
|
+
|
133
|
+
</div>
|
134
|
+
|
135
|
+
<div class="content"><div class='highlight'><pre> <span class="class"><span class="keyword">class</span> <span class="title">Todolist</span> <span class="inheritance">< <span class="parent">Rapidash::Base</span></span></span>
|
136
|
+
resource <span class="symbol">:todos</span>, <span class="symbol">class_name:</span> <span class="string">'Bcx::Resources::Todo'</span>
|
137
|
+
|
138
|
+
collection <span class="symbol">:completed</span>
|
139
|
+
<span class="keyword">end</span>
|
140
|
+
<span class="keyword">end</span>
|
141
|
+
<span class="keyword">end</span></pre></div></div>
|
142
|
+
|
143
|
+
</li>
|
144
|
+
|
145
|
+
</ul>
|
146
|
+
</div>
|
147
|
+
</body>
|
148
|
+
</html>
|
data/docs/version.html
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<title>version.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="bcx.html">
|
23
|
+
bcx.rb
|
24
|
+
</a>
|
25
|
+
|
26
|
+
|
27
|
+
<a class="source" href="http.html">
|
28
|
+
http.rb
|
29
|
+
</a>
|
30
|
+
|
31
|
+
|
32
|
+
<a class="source" href="oauth.html">
|
33
|
+
oauth.rb
|
34
|
+
</a>
|
35
|
+
|
36
|
+
|
37
|
+
<a class="source" href="configuration.html">
|
38
|
+
configuration.rb
|
39
|
+
</a>
|
40
|
+
|
41
|
+
|
42
|
+
<a class="source" href="person.html">
|
43
|
+
person.rb
|
44
|
+
</a>
|
45
|
+
|
46
|
+
|
47
|
+
<a class="source" href="project.html">
|
48
|
+
project.rb
|
49
|
+
</a>
|
50
|
+
|
51
|
+
|
52
|
+
<a class="source" href="todo.html">
|
53
|
+
todo.rb
|
54
|
+
</a>
|
55
|
+
|
56
|
+
|
57
|
+
<a class="source" href="todolist.html">
|
58
|
+
todolist.rb
|
59
|
+
</a>
|
60
|
+
|
61
|
+
|
62
|
+
<a class="source" href="response_error.html">
|
63
|
+
response_error.rb
|
64
|
+
</a>
|
65
|
+
|
66
|
+
|
67
|
+
<a class="source" href="version.html">
|
68
|
+
version.rb
|
69
|
+
</a>
|
70
|
+
|
71
|
+
</div>
|
72
|
+
</li>
|
73
|
+
</ul>
|
74
|
+
|
75
|
+
<ul class="sections">
|
76
|
+
|
77
|
+
<li id="title">
|
78
|
+
<div class="annotation">
|
79
|
+
<h1>version.rb</h1>
|
80
|
+
</div>
|
81
|
+
</li>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
<li id="section-1">
|
86
|
+
<div class="annotation">
|
87
|
+
|
88
|
+
<div class="pilwrap ">
|
89
|
+
<a class="pilcrow" href="#section-1">¶</a>
|
90
|
+
</div>
|
91
|
+
|
92
|
+
</div>
|
93
|
+
|
94
|
+
<div class="content"><div class='highlight'><pre><span class="class"><span class="keyword">module</span> <span class="title">Bcx</span></span>
|
95
|
+
<span class="constant">VERSION</span> = <span class="string">"0.0.2"</span>
|
96
|
+
<span class="keyword">end</span></pre></div></div>
|
97
|
+
|
98
|
+
</li>
|
99
|
+
|
100
|
+
</ul>
|
101
|
+
</div>
|
102
|
+
</body>
|
103
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Bcx
|
2
|
+
module Client
|
3
|
+
class HTTP < Rapidash::Client
|
4
|
+
method :http
|
5
|
+
|
6
|
+
extension :json
|
7
|
+
encode_post_data_with :json
|
8
|
+
|
9
|
+
raise_errors
|
10
|
+
|
11
|
+
resource :projects, class_name: 'Bcx::Resources::Project'
|
12
|
+
resource :todolists, class_name: 'Bcx::Resources::Todolist'
|
13
|
+
resource :people, class_name: 'Bcx::Resources::Person'
|
14
|
+
|
15
|
+
def initialize(options = {})
|
16
|
+
@account = Bcx.configuration.account
|
17
|
+
@api_version = Bcx.configuration.api_version
|
18
|
+
|
19
|
+
self.class.site("https://basecamp.com/#{@account}/api/#{@api_version}/")
|
20
|
+
|
21
|
+
super(options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Bcx
|
2
|
+
module Client
|
3
|
+
class OAuth < Rapidash::Client
|
4
|
+
method :oauth
|
5
|
+
|
6
|
+
extension :json
|
7
|
+
encode_post_data_with :json
|
8
|
+
|
9
|
+
raise_errors
|
10
|
+
|
11
|
+
resource :projects, class_name: 'Bcx::Resources::Project'
|
12
|
+
resource :todolists, class_name: 'Bcx::Resources::Todolist'
|
13
|
+
resource :people, class_name: 'Bcx::Resources::Person'
|
14
|
+
|
15
|
+
def initialize(options = {})
|
16
|
+
@account = Bcx.configuration.account
|
17
|
+
@api_version = Bcx.configuration.api_version
|
18
|
+
|
19
|
+
options[:site] = "https://basecamp.com/#{@account}/api/#{@api_version}"
|
20
|
+
options[:uid] ||= options[:client_id]
|
21
|
+
options[:secret] ||= options[:client_secret]
|
22
|
+
|
23
|
+
super(options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/bcx/resources/person.rb
CHANGED
@@ -1,13 +1,36 @@
|
|
1
|
+
# `Bcx::Resources::Person`
|
2
|
+
# Provides access to people resource
|
3
|
+
#
|
4
|
+
# #### Get all people on the account
|
5
|
+
# `GET /people.json`
|
6
|
+
#
|
7
|
+
# client.people!
|
8
|
+
#
|
9
|
+
# #### Get a person
|
10
|
+
# `GET /people/123.json`
|
11
|
+
#
|
12
|
+
# client.people!(123)
|
13
|
+
#
|
14
|
+
# #### Get the current person
|
15
|
+
# `GET /people/me.json`
|
16
|
+
#
|
17
|
+
# client.people.me!
|
18
|
+
#
|
19
|
+
# #### Get assigned todos for a person
|
20
|
+
# `GET /people/1/assigned_todos.json`
|
21
|
+
#
|
22
|
+
# client.people(1).assigned_todos
|
23
|
+
#
|
24
|
+
# #### Delete a person
|
25
|
+
# `DELETE /people/123.json`
|
26
|
+
#
|
27
|
+
# client.people(123).delete!
|
28
|
+
#
|
1
29
|
module Bcx
|
2
30
|
module Resources
|
3
|
-
|
4
|
-
# Get todolists with assigned todos for a person
|
5
|
-
# GET /people/1/assigned_todos.json
|
6
|
-
#
|
7
|
-
# client.people(1).assigned_todos
|
8
|
-
#
|
9
31
|
class Person < Rapidash::Base
|
10
|
-
|
32
|
+
url :people
|
33
|
+
collection :me
|
11
34
|
end
|
12
35
|
end
|
13
36
|
end
|
@@ -7,41 +7,38 @@ module Bcx
|
|
7
7
|
# Fetch all projects
|
8
8
|
# GET /projects.json
|
9
9
|
#
|
10
|
-
#
|
10
|
+
# client.projects!
|
11
11
|
#
|
12
12
|
# Fetch archived projects
|
13
13
|
# GET /projects/archived.json
|
14
14
|
#
|
15
|
-
#
|
15
|
+
# clients.projects.archived!
|
16
16
|
#
|
17
17
|
# Fetch single project with ID of 123
|
18
18
|
# GET /projects/123.json
|
19
19
|
#
|
20
|
-
#
|
20
|
+
# client.projects!(123)
|
21
21
|
#
|
22
22
|
# Create a project
|
23
23
|
# POST /projects.json
|
24
24
|
#
|
25
|
-
#
|
25
|
+
# client.projects.create!(name: 'Acme project', description: 'This is a new project')
|
26
26
|
#
|
27
27
|
# Update an existing project
|
28
28
|
# PUT /projects/123.json
|
29
29
|
#
|
30
|
-
#
|
30
|
+
# client.projects(123).update!(description: 'A new description')
|
31
31
|
#
|
32
32
|
# Delete a project
|
33
33
|
# DELETE /projects/123.json
|
34
34
|
#
|
35
|
-
#
|
35
|
+
# client.projects(123).delete!
|
36
36
|
#
|
37
37
|
class Project < Rapidash::Base
|
38
38
|
resource :todolists
|
39
39
|
resource :todos
|
40
40
|
|
41
|
-
|
42
|
-
@url += '/archived'
|
43
|
-
call!
|
44
|
-
end
|
41
|
+
collection :archived
|
45
42
|
end
|
46
43
|
end
|
47
44
|
end
|
@@ -34,13 +34,20 @@ module Bcx
|
|
34
34
|
#
|
35
35
|
# client.projects(123).todolists.create!(name: 'My todolist', description: 'This is a todolist')
|
36
36
|
#
|
37
|
+
# Update an existing todolist
|
38
|
+
# PUT /projects/123/todolists/456.json
|
39
|
+
#
|
40
|
+
# client.projects(123).todolists(456).update!(name: 'Updated todolist')
|
41
|
+
#
|
42
|
+
# Delete a todolist
|
43
|
+
# DELETE /projects/123/todolists/456.json
|
44
|
+
#
|
45
|
+
# client.projects(123).todolists(456).delete!
|
46
|
+
#
|
37
47
|
class Todolist < Rapidash::Base
|
38
48
|
resource :todos, class_name: 'Bcx::Resources::Todo'
|
39
49
|
|
40
|
-
|
41
|
-
@url += '/completed'
|
42
|
-
call!
|
43
|
-
end
|
50
|
+
collection :completed
|
44
51
|
end
|
45
52
|
end
|
46
53
|
end
|
data/lib/bcx/version.rb
CHANGED
data/lib/bcx.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'rapidash'
|
2
2
|
require 'bcx/version'
|
3
3
|
|
4
|
+
# # Bcx
|
5
|
+
# Fully-fledged Ruby API wrapper for Basecamp Next
|
6
|
+
#
|
7
|
+
# See the [README](https://github.com/paulspringett/bcx#readme) for usage
|
8
|
+
#
|
4
9
|
module Bcx
|
5
10
|
autoload :Configuration, 'bcx/configuration'
|
6
11
|
|
@@ -8,19 +13,25 @@ module Bcx
|
|
8
13
|
autoload :Todo, 'bcx/resources/todo'
|
9
14
|
autoload :Todolist, 'bcx/resources/todolist'
|
10
15
|
autoload :Project, 'bcx/resources/project'
|
16
|
+
autoload :Person, 'bcx/resources/person'
|
11
17
|
end
|
12
18
|
|
13
|
-
|
19
|
+
module Client
|
20
|
+
autoload :HTTP, 'bcx/client/http'
|
21
|
+
autoload :OAuth, 'bcx/client/oauth'
|
22
|
+
end
|
14
23
|
|
15
24
|
class << self
|
16
25
|
attr_accessor :configuration
|
17
26
|
end
|
18
27
|
|
28
|
+
# Expose configuration block
|
19
29
|
def self.configure
|
20
30
|
self.configuration ||= Configuration.new
|
21
31
|
yield(configuration)
|
22
32
|
end
|
23
33
|
end
|
24
34
|
|
35
|
+
# Use custom `Bcx::ResponseError` on top of Rapidash's error handling
|
25
36
|
require 'bcx/response_error'
|
26
37
|
Rapidash.response_exception_class = Bcx::ResponseError
|
data/spec/bcx/client_spec.rb
CHANGED
@@ -2,9 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Bcx::Client do
|
4
4
|
|
5
|
-
|
5
|
+
context "http auth" do
|
6
|
+
let(:client) { Bcx::Client::HTTP.new(login: 'bcx-test-user', password: 'secret') }
|
6
7
|
|
7
|
-
describe "http auth" do
|
8
8
|
it "should assign login" do
|
9
9
|
expect(client.login).to eq 'bcx-test-user'
|
10
10
|
end
|
@@ -18,23 +18,28 @@ describe Bcx::Client do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
# expect { client.projects.create!(name: '') }.to raise_error { |error|
|
24
|
-
# expect(error).to be_a Bcx::ResponseError
|
25
|
-
# expect(error.status).to eq 422
|
26
|
-
# }
|
27
|
-
# end
|
28
|
-
|
29
|
-
# Rescue a response error example
|
30
|
-
# begin
|
31
|
-
# project = client.projects.create!(name: 'foo')
|
32
|
-
# rescue Bcx::ResponseError => response
|
33
|
-
# puts response.status
|
34
|
-
# => 422
|
35
|
-
# puts response.body
|
36
|
-
# => "Name cannot be blank"
|
37
|
-
# end
|
21
|
+
context "oauth" do
|
22
|
+
let(:client) { Bcx::Client::OAuth.new(client_id: '748cc9c949af86f2e3fb35564f7e209b1d2c27d2', client_secret: '7fba79ec3bf1eb9e278098031414e5a3a41ec842', access_token: 'BAhbByIBsHsiZXhwaXJlc19hdCI6IjIwMTMtMDctMDFUMjE6MTI6MDFaIiwidXNlcl9pZHMiOlsxNzE3NDMwNV0sImNsaWVudF9pZCI6Ijc0OGNjOWM5NDlhZjg2ZjJlM2ZiMzU1NjRmN2UyMDliMWQyYzI3ZDIiLCJ2ZXJzaW9uIjoxLCJhcGlfZGVhZGJvbHQiOiJmZmE1OTgzMzQ3YTY2MWExM2Y1YWE3YTM0ODVhYzk4YiJ9dToJVGltZQ01WBzApGcWMA==--20fd0c6159b19ee6689e149590b14be5fd98bb3b') }
|
38
23
|
|
24
|
+
it "should assign credentials" do
|
25
|
+
expect(client.uid).to eq '748cc9c949af86f2e3fb35564f7e209b1d2c27d2'
|
26
|
+
expect(client.secret).to eq '7fba79ec3bf1eb9e278098031414e5a3a41ec842'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should provide an access token" do
|
30
|
+
expect(client.access_token).not_to be_nil
|
31
|
+
end
|
32
|
+
end
|
39
33
|
|
34
|
+
describe "error handling", :vcr do
|
35
|
+
let(:client) { Bcx::Client::HTTP.new(login: 'bcx-test-user', password: 'secret') }
|
36
|
+
|
37
|
+
it "should raise exception" do
|
38
|
+
expect { client.projects.create!(name: '') }.to raise_error { |response|
|
39
|
+
expect(response).to be_a Bcx::ResponseError
|
40
|
+
expect(response.status).to eq 422
|
41
|
+
expect(response.errors).to include("name can't be blank")
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
40
45
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bcx::Resources::Person, :vcr do
|
4
|
+
let(:client) { Bcx::Client::HTTP.new(login: 'bcx-test-user', password: 'secret') }
|
5
|
+
|
6
|
+
describe "GET /people.json" do
|
7
|
+
let(:people) { client.people! }
|
8
|
+
|
9
|
+
it "should be an array" do
|
10
|
+
expect(people).to be_an Array
|
11
|
+
end
|
12
|
+
|
13
|
+
it "first person should have the correct id" do
|
14
|
+
expect(people.first.id).to eq 4666033
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "GET /people/4666033.json" do
|
19
|
+
let(:person) { client.people!(4666033) }
|
20
|
+
|
21
|
+
it "should return a hash" do
|
22
|
+
expect(person).to be_a Hashie::Mash
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have the correct id" do
|
26
|
+
expect(person.id).to eq 4666033
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "GET /people/me.json" do
|
31
|
+
let(:person) { client.people.me! }
|
32
|
+
|
33
|
+
it "should return a hash" do
|
34
|
+
expect(person).to be_a Hashie::Mash
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have the correct id" do
|
38
|
+
expect(person.id).to eq 4666033
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have assigned todos" do
|
42
|
+
expect(person.assigned_todos).to be_a Hashie::Mash
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "DELETE /people/4904728.json" do
|
47
|
+
it "should delete a todolist" do
|
48
|
+
client.people(4904728).delete!
|
49
|
+
expect { client.people!(4904728) }.to raise_error { |error|
|
50
|
+
expect(error).to be_a Bcx::ResponseError
|
51
|
+
expect(error.status).to eq 404
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/bcx/project_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Bcx::Resources::Project, :vcr do
|
4
|
-
let(:client) { Bcx::Client.new(
|
4
|
+
let(:client) { Bcx::Client::HTTP.new(login: 'bcx-test-user', password: 'secret') }
|
5
5
|
|
6
6
|
describe "GET /projects" do
|
7
7
|
let(:projects) { client.projects! }
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bcx::Resources::Todo, :vcr do
|
4
|
+
let(:client) { Bcx::Client::HTTP.new(login: 'bcx-test-user', password: 'secret') }
|
5
|
+
|
6
|
+
describe "POST /projects/2951531/todolists/8268819/todos.json" do
|
7
|
+
it "should create a new todo" do
|
8
|
+
todo = client.projects(2951531).todolists(8268819).todos.create!(content: 'My todo')
|
9
|
+
expect(todo.created_at).not_to be_blank
|
10
|
+
expect(todo.content).to eq 'My todo'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "GET /projects/2951531/todos/48545200.json" do
|
15
|
+
let(:todo) { client.projects(2951531).todos!(48545200) }
|
16
|
+
|
17
|
+
it "should return a hash" do
|
18
|
+
expect(todo).to be_a Hashie::Mash
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have the correct id" do
|
22
|
+
expect(todo.id).to eq 48545200
|
23
|
+
expect(todo.content).to eq 'First todo'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "PUT /projects/2951531/todos/48545200.json" do
|
28
|
+
it "should update an existing todo" do
|
29
|
+
todo = client.projects(2951531).todos(48545200).update!(content: 'My updated todo')
|
30
|
+
expect(todo.content).to eq 'My updated todo'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "DELETE /projects/2951531/todos/48545200.json" do
|
35
|
+
it "should delete the given todo" do
|
36
|
+
client.projects(2951531).todos(48545200).delete!
|
37
|
+
expect { client.projects(2951531).todos!(48545200) }.to raise_error { |error|
|
38
|
+
expect(error).to be_a Bcx::ResponseError
|
39
|
+
expect(error.status).to eq 404
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/bcx/todolist_spec.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Bcx::Resources::Todolist, :vcr do
|
4
|
-
let(:client) { Bcx::Client.new(
|
5
|
-
|
4
|
+
let(:client) { Bcx::Client::HTTP.new(login: 'bcx-test-user', password: 'secret') }
|
6
5
|
|
7
6
|
describe "GET /projects/2937644/todolists.json" do
|
8
7
|
let(:todolists) { client.projects(2956584).todolists! }
|
@@ -66,10 +65,27 @@ describe Bcx::Resources::Todolist, :vcr do
|
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
69
|
-
describe "/projects/123/todolists.json" do
|
68
|
+
describe "POST /projects/123/todolists.json" do
|
70
69
|
it "should create a new todolist" do
|
71
70
|
todolist = client.projects(2956584).todolists.create!(name: 'My todolist', description: 'This is a todolist')
|
72
71
|
expect(todolist.created_at).not_to be_blank
|
73
72
|
end
|
74
73
|
end
|
74
|
+
|
75
|
+
describe "PUT /projects/2956584/todolists/8268819.json" do
|
76
|
+
it "should create a new todolist" do
|
77
|
+
todolist = client.projects(2951531).todolists(8268819).update!(name: 'Renamed todolist')
|
78
|
+
expect(todolist.name).to eq 'Renamed todolist'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "DELETE /projects/2956584/todolists/8268819.json" do
|
83
|
+
it "should delete a todolist" do
|
84
|
+
client.projects(2951531).todolists(8268819).delete!
|
85
|
+
expect { client.projects(2951531).todolists!(8268819) }.to raise_error { |error|
|
86
|
+
expect(error).to be_a Bcx::ResponseError
|
87
|
+
expect(error.status).to eq 404
|
88
|
+
}
|
89
|
+
end
|
90
|
+
end
|
75
91
|
end
|