camper 0.0.11 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +16 -16
- data/README.md +5 -3
- data/examples/comments.rb +12 -1
- data/examples/message_types.rb +29 -0
- data/examples/messages.rb +13 -2
- data/lib/camper/api/comments.rb +80 -8
- data/lib/camper/api/message_board.rb +23 -0
- data/lib/camper/api/message_types.rb +90 -0
- data/lib/camper/api/messages.rb +103 -4
- data/lib/camper/api/people.rb +86 -84
- data/lib/camper/api/projects.rb +101 -101
- data/lib/camper/api/resource.rb +6 -4
- data/lib/camper/api/todolists.rb +84 -92
- data/lib/camper/api/todos.rb +161 -183
- data/lib/camper/client.rb +3 -1
- data/lib/camper/error.rb +2 -0
- data/lib/camper/paginated_response.rb +2 -0
- data/lib/camper/request.rb +1 -0
- data/lib/camper/version.rb +1 -1
- metadata +5 -2
data/lib/camper/api/todos.rb
CHANGED
@@ -1,198 +1,176 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
raise Camper::Error::InvalidParameter, todolist unless Camper::UrlUtils.basecamp_url?(url)
|
34
|
-
|
35
|
-
get(url, query: options, override_path: true)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Get a todo with a given id using a particular parent resource.
|
39
|
-
#
|
40
|
-
# @example
|
41
|
-
# client.todo(my_project, '10')
|
42
|
-
# @example
|
43
|
-
# client.todo(new_todolist, 134)
|
44
|
-
# @example
|
45
|
-
# client.todo(67543, '2440')
|
46
|
-
#
|
47
|
-
# @param parent [Integer|String|Project|Resource] can be either a project id, a project or a todolist resource
|
48
|
-
# @param id [Integer|String] id of the todo
|
49
|
-
# @return [Resource]
|
50
|
-
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#get-a-to-do
|
51
|
-
def todo(parent, id)
|
52
|
-
bucket_id = parent
|
53
|
-
|
54
|
-
if parent.is_a? Camper::Project
|
55
|
-
bucket_id = parent.id
|
56
|
-
elsif parent.respond_to?(:type)
|
57
|
-
bucket_id = parent.bucket.id
|
3
|
+
module Camper
|
4
|
+
class Client
|
5
|
+
# Defines methods related to todos.
|
6
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md
|
7
|
+
module TodosAPI
|
8
|
+
PARAMETERS = %w[
|
9
|
+
content
|
10
|
+
description
|
11
|
+
assignee_ids
|
12
|
+
completion_subscriber_ids
|
13
|
+
notify
|
14
|
+
due_on
|
15
|
+
starts_on
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
# Get the todos in a todolist
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# client.todos(todolist)
|
22
|
+
# @example
|
23
|
+
# client.todos(todolist, completed: true)
|
24
|
+
#
|
25
|
+
# @param todolist [Resource] the parent todolist resource
|
26
|
+
# @param options [Hash] options to filter the list of todos
|
27
|
+
# @return [Resource]
|
28
|
+
# @raise [Error::InvalidParameter] if todos_url field in todolist param
|
29
|
+
# is not a valid basecamp url
|
30
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#get-to-dos
|
31
|
+
def todos(todolist, options = {})
|
32
|
+
get(todolist.todos_url, query: options, override_path: true)
|
58
33
|
end
|
59
34
|
|
60
|
-
|
61
|
-
|
35
|
+
# Get a todo with a given id using a particular parent resource.
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# client.todo(my_project, '10')
|
39
|
+
# @example
|
40
|
+
# client.todo(new_todolist, 134)
|
41
|
+
# @example
|
42
|
+
# client.todo(67543, '2440')
|
43
|
+
#
|
44
|
+
# @param parent [Integer|String|Project|Resource] can be either a project id, a project or a todolist resource
|
45
|
+
# @param id [Integer|String] id of the todo
|
46
|
+
# @return [Resource]
|
47
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#get-a-to-do
|
48
|
+
def todo(parent, id)
|
49
|
+
bucket_id = parent
|
50
|
+
|
51
|
+
if parent.is_a? Camper::Project
|
52
|
+
bucket_id = parent.id
|
53
|
+
elsif parent.respond_to?(:type)
|
54
|
+
bucket_id = parent.bucket.id
|
55
|
+
end
|
56
|
+
|
57
|
+
get("/buckets/#{bucket_id}/todos/#{id}")
|
58
|
+
end
|
62
59
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
post(url, body: { content: content, **options }, override_path: true)
|
89
|
-
end
|
60
|
+
# Create a todo within a todolist
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
# client.create_todo(todolist, 'First Todo')
|
64
|
+
# @example
|
65
|
+
# client.create_todo(
|
66
|
+
# todolist,
|
67
|
+
# 'Program it',
|
68
|
+
# description: "<div><em>Try that new language!</em></div>, due_on: "2016-05-01"
|
69
|
+
# )
|
70
|
+
#
|
71
|
+
# @param todolist [Resource] the todolist where the todo is going to be created
|
72
|
+
# @param content [String] what the to-do is for
|
73
|
+
# @param options [Hash] extra parameters for the todo such as due_date and description
|
74
|
+
# @return [Resource]
|
75
|
+
# @raise [Error::InvalidParameter] if todos_url field in todolist param
|
76
|
+
# is not a valid basecamp url
|
77
|
+
# @raise [Error::InvalidParameter] if content parameter is blank
|
78
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#create-a-to-do
|
79
|
+
def create_todo(todolist, content, options = {})
|
80
|
+
raise Error::InvalidParameter, content if content.blank?
|
81
|
+
|
82
|
+
post(todolist.todos_url, body: { content: content, **options }, override_path: true)
|
83
|
+
end
|
90
84
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
PARAMETERS.each { |p| body[p.to_sym] = todo[p] unless key_is_present?(body, p) }
|
118
|
-
|
119
|
-
put(url, body: body, override_path: true)
|
120
|
-
end
|
85
|
+
# Update a todo.
|
86
|
+
#
|
87
|
+
# @example
|
88
|
+
# client.update_todo(todo, 'Todo')
|
89
|
+
# @example
|
90
|
+
# client.update_todo(
|
91
|
+
# todo,
|
92
|
+
# 'Program it',
|
93
|
+
# description: "<div><em>Try that new language!</em></div>,
|
94
|
+
# due_on: "2016-05-01",
|
95
|
+
# starts_on: "2016-04-30"
|
96
|
+
# )
|
97
|
+
#
|
98
|
+
# @param todo [Resource] the todo to be updated
|
99
|
+
# @param options [Hash] parameters to be changed. The ones that are not specified
|
100
|
+
# will be set to the current values of the todo object
|
101
|
+
# @return [Resource]
|
102
|
+
# @raise [Error::InvalidParameter] if url field in todo param
|
103
|
+
# is not a valid basecamp url
|
104
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#update-a-to-do
|
105
|
+
def update_todo(todo, options)
|
106
|
+
body = {}.merge(options)
|
107
|
+
PARAMETERS.each { |p| body[p.to_sym] = todo[p] unless key_is_present?(body, p) }
|
108
|
+
|
109
|
+
put(todo.url, body: body, override_path: true)
|
110
|
+
end
|
121
111
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
raise Camper::Error::InvalidParameter, todo unless Camper::UrlUtils.basecamp_url?(url)
|
135
|
-
|
136
|
-
post("#{url}/completion", override_path: true)
|
137
|
-
end
|
112
|
+
# Complete a todo
|
113
|
+
#
|
114
|
+
# @example
|
115
|
+
# client.complete_todo(todo)
|
116
|
+
#
|
117
|
+
# @param todo [Resource] the todo to be marked as completed
|
118
|
+
# @raise [Error::InvalidParameter] if url field in todo param
|
119
|
+
# is not a valid basecamp url
|
120
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#complete-a-to-do
|
121
|
+
def complete_todo(todo)
|
122
|
+
post("#{todo.url}/completion", override_path: true)
|
123
|
+
end
|
138
124
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
raise Camper::Error::InvalidParameter, todo unless Camper::UrlUtils.basecamp_url?(url)
|
152
|
-
|
153
|
-
delete("#{url}/completion", override_path: true)
|
154
|
-
end
|
125
|
+
# Uncomplete a todo
|
126
|
+
#
|
127
|
+
# @example
|
128
|
+
# client.uncomplete_todo(todo)
|
129
|
+
#
|
130
|
+
# @param todo [Resource] the todo to be marked as uncompleted
|
131
|
+
# @raise [Error::InvalidParameter] if url field in todo param
|
132
|
+
# is not a valid basecamp url
|
133
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#uncomplete-a-to-do
|
134
|
+
def uncomplete_todo(todo)
|
135
|
+
delete("#{todo.url}/completion", override_path: true)
|
136
|
+
end
|
155
137
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
put("#{url}/position", position: position, override_path: true)
|
174
|
-
end
|
138
|
+
# Reposition a todo
|
139
|
+
#
|
140
|
+
# @example
|
141
|
+
# client.uncomplete_todo(todo)
|
142
|
+
#
|
143
|
+
# @param todo [Resource] the todo to be repositioned
|
144
|
+
# @param position [Integer|String] new position for the todo
|
145
|
+
# @raise [Error::InvalidParameter] if url field in todo param
|
146
|
+
# is not a valid basecamp url
|
147
|
+
# @raise [Error::InvalidParameter] if position param is less than 1
|
148
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#reposition-a-to-do
|
149
|
+
def reposition_todo(todo, position)
|
150
|
+
raise Error::InvalidParameter, position if position.to_i < 1
|
151
|
+
|
152
|
+
put("#{todo.url}/position", position: position, override_path: true)
|
153
|
+
end
|
175
154
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
trash_recording(todo)
|
190
|
-
end
|
155
|
+
# Trash a todo
|
156
|
+
# it calls the trash_recording endpoint under the hood
|
157
|
+
#
|
158
|
+
# @example
|
159
|
+
# client.trash_todo(todo)
|
160
|
+
#
|
161
|
+
# @param todo [Resource] the todo to be trashed
|
162
|
+
# @raise [Error::InvalidParameter] if url field in todo param
|
163
|
+
# is not a valid basecamp url
|
164
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/recordings.md#trash-a-recording
|
165
|
+
def trash_todo(todo)
|
166
|
+
trash_recording(todo)
|
167
|
+
end
|
191
168
|
|
192
|
-
|
169
|
+
private
|
193
170
|
|
194
|
-
|
195
|
-
|
171
|
+
def key_is_present?(hash, key)
|
172
|
+
hash.key?(key.to_sym) || hash.key?(key.to_s)
|
173
|
+
end
|
196
174
|
end
|
197
175
|
end
|
198
176
|
end
|
data/lib/camper/client.rb
CHANGED
@@ -14,6 +14,8 @@ module Camper
|
|
14
14
|
include Authorization
|
15
15
|
include CommentsAPI
|
16
16
|
include Logging
|
17
|
+
include MessageBoardsAPI
|
18
|
+
include MessageTypesAPI
|
17
19
|
include MessagesAPI
|
18
20
|
include PeopleAPI
|
19
21
|
include ProjectsAPI
|
@@ -44,7 +46,7 @@ module Camper
|
|
44
46
|
# by yielding the config object to the block
|
45
47
|
# @return [Camper::Client] the client instance being configured
|
46
48
|
def configure
|
47
|
-
yield @config
|
49
|
+
yield @config if block_given?
|
48
50
|
|
49
51
|
self
|
50
52
|
end
|
data/lib/camper/error.rb
CHANGED
data/lib/camper/request.rb
CHANGED
data/lib/camper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- renehernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- camper.gemspec
|
124
124
|
- examples/comments.rb
|
125
125
|
- examples/create_and_complete_todo.rb
|
126
|
+
- examples/message_types.rb
|
126
127
|
- examples/messages.rb
|
127
128
|
- examples/oauth.rb
|
128
129
|
- examples/obtain_acces_token.rb
|
@@ -133,6 +134,8 @@ files:
|
|
133
134
|
- examples/todos.rb
|
134
135
|
- lib/camper.rb
|
135
136
|
- lib/camper/api/comments.rb
|
137
|
+
- lib/camper/api/message_board.rb
|
138
|
+
- lib/camper/api/message_types.rb
|
136
139
|
- lib/camper/api/messages.rb
|
137
140
|
- lib/camper/api/people.rb
|
138
141
|
- lib/camper/api/projects.rb
|