camper 0.0.11 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,198 +1,176 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Camper::Client
4
- # Defines methods related to todos.
5
- # @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md
6
- module TodosAPI
7
- PARAMETERS = %w[
8
- content
9
- description
10
- assignee_ids
11
- completion_subscriber_ids
12
- notify
13
- due_on
14
- starts_on
15
- ].freeze
16
-
17
- # Get the todos in a todolist
18
- #
19
- # @example
20
- # client.todos(todolist)
21
- # @example
22
- # client.todos(todolist, completed: true)
23
- #
24
- # @param todolist [Resource] the parent todoset resource
25
- # @param options [Hash] options to filter the list of todos
26
- # @return [Resource]
27
- # @raise [Error::InvalidParameter] if todos_url field in todolist param
28
- # is not a valid basecamp url
29
- # @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#get-to-dos
30
- def todos(todolist, options = {})
31
- url = todolist.todos_url
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
- get("/buckets/#{bucket_id}/todos/#{id}")
61
- end
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
- # Create a todo within a todolist
64
- #
65
- # @example
66
- # client.create_todo(todolist, 'First Todo')
67
- # @example
68
- # client.create_todo(
69
- # todolist,
70
- # 'Program it',
71
- # description: "<div><em>Try that new language!</em></div>, due_on: "2016-05-01"
72
- # )
73
- #
74
- # @param todolist [Resource] the todolist where the todo is going to be created
75
- # @param content [String] what the to-do is for
76
- # @param options [Hash] extra parameters for the todo such as due_date and description
77
- # @return [Resource]
78
- # @raise [Error::InvalidParameter] if todos_url field in todolist param
79
- # is not a valid basecamp url
80
- # @raise [Error::InvalidParameter] if content parameter is blank
81
- # @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#create-a-to-do
82
- def create_todo(todolist, content, options = {})
83
- url = todolist.todos_url
84
-
85
- raise Camper::Error::InvalidParameter, todolist unless Camper::UrlUtils.basecamp_url?(url)
86
- raise Camper::Error::InvalidParameter, content if content.blank?
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
- # Update a todo.
92
- #
93
- # @example
94
- # client.update_todo(todo, 'Todo')
95
- # @example
96
- # client.update_todo(
97
- # todo,
98
- # 'Program it',
99
- # description: "<div><em>Try that new language!</em></div>,
100
- # due_on: "2016-05-01",
101
- # starts_on: "2016-04-30"
102
- # )
103
- #
104
- # @param todo [Resource] the todo to be updated
105
- # @param options [Hash] parameters to be changed. The ones that are not specified
106
- # will be set to the current values of the todo object
107
- # @return [Resource]
108
- # @raise [Error::InvalidParameter] if url field in todo param
109
- # is not a valid basecamp url
110
- # @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#update-a-to-do
111
- def update_todo(todo, options)
112
- url = todo.url
113
-
114
- raise Camper::Error::InvalidParameter, url unless Camper::UrlUtils.basecamp_url?(url)
115
-
116
- body = {}.merge(options)
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
- # Complete a todo
123
- #
124
- # @example
125
- # client.complete_todo(todo)
126
- #
127
- # @param todo [Resource] the todo to be marked as completed
128
- # @raise [Error::InvalidParameter] if url field in todo param
129
- # is not a valid basecamp url
130
- # @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#complete-a-to-do
131
- def complete_todo(todo)
132
- url = todo.url
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
- # Uncomplete a todo
140
- #
141
- # @example
142
- # client.uncomplete_todo(todo)
143
- #
144
- # @param todo [Resource] the todo to be marked as uncompleted
145
- # @raise [Error::InvalidParameter] if url field in todo param
146
- # is not a valid basecamp url
147
- # @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#uncomplete-a-to-do
148
- def uncomplete_todo(todo)
149
- url = todo.url
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
- # Reposition a todo
157
- #
158
- # @example
159
- # client.uncomplete_todo(todo)
160
- #
161
- # @param todo [Resource] the todo to be repositioned
162
- # @param position [Integer|String] new position for the todo
163
- # @raise [Error::InvalidParameter] if url field in todo param
164
- # is not a valid basecamp url
165
- # @raise [Error::InvalidParameter] if position param is less than 1
166
- # @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#reposition-a-to-do
167
- def reposition_todo(todo, position)
168
- url = todo.url
169
- raise Camper::Error::InvalidParameter, todo unless Camper::UrlUtils.basecamp_url?(url)
170
-
171
- raise Camper::Error::InvalidParameter, position if position.to_i < 1
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
- # Trash a todo
177
- # it calls the trash_recording endpoint under the hood
178
- #
179
- # @example
180
- # client.trash_todo(todo)
181
- #
182
- # @param todo [Resource] the todo to be trashed
183
- # @raise [Error::InvalidParameter] if url field in todo param
184
- # is not a valid basecamp url
185
- # @see https://github.com/basecamp/bc3-api/blob/master/sections/recordings.md#trash-a-recording
186
- def trash_todo(todo)
187
- raise Camper::Error::InvalidParameter, todo unless Camper::UrlUtils.basecamp_url?(todo.url)
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
- private
169
+ private
193
170
 
194
- def key_is_present?(hash, key)
195
- hash.key?(key.to_sym) || hash.key?(key.to_s)
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
@@ -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
@@ -17,6 +17,8 @@ module Camper
17
17
 
18
18
  class RequestIsMissingParameters < Error; end
19
19
 
20
+ class InvalidURL < Error; end
21
+
20
22
  class InvalidParameter < Error; end
21
23
 
22
24
  # Raised when impossible to parse response body.
@@ -51,9 +51,11 @@ module Camper
51
51
 
52
52
  private
53
53
 
54
+ # rubocop:disable Lint/ToEnumArguments
54
55
  def lazy_paginate
55
56
  to_enum(:each_page).lazy.flat_map(&:to_ary)
56
57
  end
58
+ # rubocop:enable Lint/ToEnumArguments
57
59
 
58
60
  def each_page
59
61
  current = self
@@ -63,6 +63,7 @@ module Camper
63
63
  def execute
64
64
  endpoint, params = prepare_request_data
65
65
 
66
+ raise Error::InvalidURL, endpoint unless UrlUtils.basecamp_url?(endpoint)
66
67
  raise Error::TooManyRetries, endpoint if maxed_attempts?
67
68
 
68
69
  @attempts += 1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Camper
4
- VERSION = '0.0.11'
4
+ VERSION = '0.1.0'
5
5
  end
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.11
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-01 00:00:00.000000000 Z
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