camper 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.rubocop.yml +10 -0
- data/CHANGELOG.md +62 -1
- data/Gemfile.lock +22 -23
- data/README.md +16 -0
- data/camper.gemspec +1 -0
- data/examples/comments.rb +12 -1
- data/examples/message_types.rb +29 -0
- data/examples/messages.rb +13 -2
- data/examples/people.rb +11 -0
- data/examples/projects.rb +12 -0
- data/examples/recordings.rb +13 -0
- data/examples/todolists.rb +50 -0
- data/examples/todos.rb +21 -6
- data/lib/camper.rb +2 -0
- data/lib/camper/api/comments.rb +87 -0
- data/lib/camper/api/message_board.rb +23 -0
- data/lib/camper/api/message_types.rb +90 -0
- data/lib/camper/api/messages.rb +108 -0
- data/lib/camper/api/people.rb +99 -0
- data/lib/camper/api/projects.rb +120 -0
- data/lib/camper/api/recordings.rb +84 -0
- data/lib/camper/api/resource.rb +6 -4
- data/lib/camper/api/todolists.rb +95 -0
- data/lib/camper/api/todos.rb +176 -0
- data/lib/camper/client.rb +10 -5
- data/lib/camper/core_extensions/object.rb +156 -0
- data/lib/camper/error.rb +8 -0
- data/lib/camper/paginated_response.rb +2 -0
- data/lib/camper/recording_types.rb +22 -0
- data/lib/camper/request.rb +3 -13
- data/lib/camper/url_utils.rb +26 -0
- data/lib/camper/version.rb +1 -1
- metadata +34 -7
- data/lib/camper/api/comment.rb +0 -13
- data/lib/camper/api/message.rb +0 -9
- data/lib/camper/api/project.rb +0 -24
- data/lib/camper/api/todo.rb +0 -80
data/lib/camper/error.rb
CHANGED
@@ -13,6 +13,14 @@ module Camper
|
|
13
13
|
|
14
14
|
class MissingBody < Error; end
|
15
15
|
|
16
|
+
class ResourceCannotBeCommented < Error; end
|
17
|
+
|
18
|
+
class RequestIsMissingParameters < Error; end
|
19
|
+
|
20
|
+
class InvalidURL < Error; end
|
21
|
+
|
22
|
+
class InvalidParameter < Error; end
|
23
|
+
|
16
24
|
# Raised when impossible to parse response body.
|
17
25
|
class Parsing < Error; end
|
18
26
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Camper
|
4
|
+
class RecordingTypes
|
5
|
+
COMMENT = 'Comment'
|
6
|
+
DOCUMENT = 'Document'
|
7
|
+
MESSAGE = 'Message'
|
8
|
+
QUESTION_ANSWER = 'Question::Answer'
|
9
|
+
SCHEDULE_ENTRY = 'Schedule::Entry'
|
10
|
+
TODO = 'Todo'
|
11
|
+
TODOLIST = 'Todolist'
|
12
|
+
UPLOAD = 'Upload'
|
13
|
+
|
14
|
+
# rubocop:disable Style/ClassVars
|
15
|
+
def self.all
|
16
|
+
@@recordings ||= constants(false).map { |c| const_get(c) }.sort
|
17
|
+
|
18
|
+
@@recordings
|
19
|
+
end
|
20
|
+
# rubocop:enable Style/ClassVars
|
21
|
+
end
|
22
|
+
end
|
data/lib/camper/request.rb
CHANGED
@@ -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
|
@@ -93,7 +94,7 @@ module Camper
|
|
93
94
|
|
94
95
|
full_endpoint = override_path ? @path : @client.api_endpoint + @path
|
95
96
|
|
96
|
-
full_endpoint =
|
97
|
+
full_endpoint = UrlUtils.transform(full_endpoint)
|
97
98
|
|
98
99
|
return full_endpoint, params
|
99
100
|
end
|
@@ -138,19 +139,8 @@ module Camper
|
|
138
139
|
{ 'Authorization' => "Bearer #{@client.access_token}" }
|
139
140
|
end
|
140
141
|
|
141
|
-
# Utility method for transforming Basecamp Web URLs into API URIs
|
142
|
-
# e.g 'https://3.basecamp.com/1/buckets/2/todos/3' will be
|
143
|
-
# converted into 'https://3.basecampapi.com/1/buckets/2/todos/3.json'
|
144
|
-
#
|
145
|
-
# @return [String]
|
146
|
-
def url_transform(url)
|
147
|
-
api_url = url.gsub('3.basecamp.com', '3.basecampapi.com')
|
148
|
-
api_url.gsub!('.json', '')
|
149
|
-
"#{api_url}.json"
|
150
|
-
end
|
151
|
-
|
152
142
|
def body_to_json?(params)
|
153
|
-
@method
|
143
|
+
%w[post put].include?(@method) && params.key?(:body)
|
154
144
|
end
|
155
145
|
end
|
156
146
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Camper
|
4
|
+
# Defines methods related to url operations.
|
5
|
+
module UrlUtils
|
6
|
+
def self.basecamp_url?(url)
|
7
|
+
return false if url.nil? || !url.is_a?(String) || url == ''
|
8
|
+
|
9
|
+
transformed_url = UrlUtils.transform(url)
|
10
|
+
|
11
|
+
transformed_url.match?(%r{#{Configuration.base_api_endpoint}/\d+/.*})
|
12
|
+
end
|
13
|
+
|
14
|
+
# Utility method for transforming Basecamp Web URLs into API URIs
|
15
|
+
# e.g 'https://3.basecamp.com/1/buckets/2/todos/3' will be
|
16
|
+
# converted into 'https://3.basecampapi.com/1/buckets/2/todos/3.json'
|
17
|
+
#
|
18
|
+
# @param url [String] url to test
|
19
|
+
# @return [String]
|
20
|
+
def self.transform(url)
|
21
|
+
api_url = url.gsub('3.basecamp.com', '3.basecampapi.com')
|
22
|
+
api_url.gsub!('.json', '')
|
23
|
+
"#{api_url}.json"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
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
|
+
date: 2020-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: concurrent-ruby
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,26 +123,39 @@ files:
|
|
109
123
|
- camper.gemspec
|
110
124
|
- examples/comments.rb
|
111
125
|
- examples/create_and_complete_todo.rb
|
126
|
+
- examples/message_types.rb
|
112
127
|
- examples/messages.rb
|
113
128
|
- examples/oauth.rb
|
114
129
|
- examples/obtain_acces_token.rb
|
130
|
+
- examples/people.rb
|
131
|
+
- examples/projects.rb
|
132
|
+
- examples/recordings.rb
|
133
|
+
- examples/todolists.rb
|
115
134
|
- examples/todos.rb
|
116
135
|
- lib/camper.rb
|
117
|
-
- lib/camper/api/
|
118
|
-
- lib/camper/api/
|
119
|
-
- lib/camper/api/
|
136
|
+
- lib/camper/api/comments.rb
|
137
|
+
- lib/camper/api/message_board.rb
|
138
|
+
- lib/camper/api/message_types.rb
|
139
|
+
- lib/camper/api/messages.rb
|
140
|
+
- lib/camper/api/people.rb
|
141
|
+
- lib/camper/api/projects.rb
|
142
|
+
- lib/camper/api/recordings.rb
|
120
143
|
- lib/camper/api/resource.rb
|
121
|
-
- lib/camper/api/
|
144
|
+
- lib/camper/api/todolists.rb
|
145
|
+
- lib/camper/api/todos.rb
|
122
146
|
- lib/camper/authorization.rb
|
123
147
|
- lib/camper/client.rb
|
124
148
|
- lib/camper/configuration.rb
|
149
|
+
- lib/camper/core_extensions/object.rb
|
125
150
|
- lib/camper/error.rb
|
126
151
|
- lib/camper/logging.rb
|
127
152
|
- lib/camper/paginated_response.rb
|
128
153
|
- lib/camper/pagination_data.rb
|
154
|
+
- lib/camper/recording_types.rb
|
129
155
|
- lib/camper/request.rb
|
130
156
|
- lib/camper/resource.rb
|
131
157
|
- lib/camper/resources/project.rb
|
158
|
+
- lib/camper/url_utils.rb
|
132
159
|
- lib/camper/version.rb
|
133
160
|
homepage: https://github.com/renehernandez/camper
|
134
161
|
licenses:
|
@@ -152,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
179
|
- !ruby/object:Gem::Version
|
153
180
|
version: '0'
|
154
181
|
requirements: []
|
155
|
-
rubygems_version: 3.1.
|
182
|
+
rubygems_version: 3.1.4
|
156
183
|
signing_key:
|
157
184
|
specification_version: 4
|
158
185
|
summary: Ruby client for Basecamp 3 API
|
data/lib/camper/api/comment.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Camper::Client
|
4
|
-
module CommentAPI
|
5
|
-
def create_comment(resource, content)
|
6
|
-
post(resource.comments_url, override_path: true, body: { content: content })
|
7
|
-
end
|
8
|
-
|
9
|
-
def comments(resource)
|
10
|
-
get(resource.comments_url, override_path: true)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/camper/api/message.rb
DELETED
data/lib/camper/api/project.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Camper::Client
|
4
|
-
module ProjectAPI
|
5
|
-
|
6
|
-
def projects(options = {})
|
7
|
-
get("/projects", options)
|
8
|
-
end
|
9
|
-
|
10
|
-
def project(id)
|
11
|
-
get("/projects/#{id}")
|
12
|
-
end
|
13
|
-
|
14
|
-
def message_board(project)
|
15
|
-
board = project.message_board
|
16
|
-
get(board.url, override_path: true)
|
17
|
-
end
|
18
|
-
|
19
|
-
def todoset(project)
|
20
|
-
todoset = project.todoset
|
21
|
-
get(todoset.url, override_path: true)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/camper/api/todo.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Camper::Client
|
4
|
-
module TodoAPI
|
5
|
-
|
6
|
-
# Get the todolists associated with the todoset
|
7
|
-
#
|
8
|
-
# @example
|
9
|
-
# client.todolists(todoset)
|
10
|
-
# @example
|
11
|
-
# client.todolists(todoset, status: 'archived')
|
12
|
-
#
|
13
|
-
# @param todoset [Resource] the parent todoset resource
|
14
|
-
# @param options [Hash] extra options to filter the list of todolist
|
15
|
-
# @return [Array<Resource>]
|
16
|
-
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md#get-to-do-lists
|
17
|
-
def todolists(todoset, options={})
|
18
|
-
get(todoset.todolists_url, options.merge(override_path: true))
|
19
|
-
end
|
20
|
-
|
21
|
-
# Get a todolist with a given id
|
22
|
-
#
|
23
|
-
# @example
|
24
|
-
# client.todolist(todoset, '2345')
|
25
|
-
#
|
26
|
-
# @param todoset [Resource] the parent todoset resource
|
27
|
-
# @param id [Integer, String] the id of the todolist to get
|
28
|
-
# @return [Resource]
|
29
|
-
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md#get-a-to-do-list
|
30
|
-
def todolist(todoset, id)
|
31
|
-
get("/buckets/#{todoset.bucket.id}/todolists/#{id}")
|
32
|
-
end
|
33
|
-
|
34
|
-
# Get the todos in a todolist
|
35
|
-
#
|
36
|
-
# @example
|
37
|
-
# client.todos(todolist)
|
38
|
-
# @example
|
39
|
-
# client.todos(todolist, completed: true)
|
40
|
-
#
|
41
|
-
# @param todolist [Resource] the parent todoset resource
|
42
|
-
# @param options [Hash] options to filter the list of todos
|
43
|
-
# @return [Resource]
|
44
|
-
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#get-to-dos
|
45
|
-
def todos(todolist, options={})
|
46
|
-
get(todolist.todos_url, options.merge(override_path: true))
|
47
|
-
end
|
48
|
-
|
49
|
-
# Create a todo within a todolist
|
50
|
-
#
|
51
|
-
# @example
|
52
|
-
# client.create_todo(todolist, 'First Todo')
|
53
|
-
# @example
|
54
|
-
# client.create_todo(
|
55
|
-
# todolist,
|
56
|
-
# 'Program it',
|
57
|
-
# description: "<div><em>Try that new language!</em></div>, due_on: "2016-05-01"
|
58
|
-
# )
|
59
|
-
#
|
60
|
-
# @param todolist [Resource] the todolist where the todo is going to be created
|
61
|
-
# @param content [String] what the to-do is for
|
62
|
-
# @param options [Hash] extra configuration for the todo such as due_date and description
|
63
|
-
# @return [Resource]
|
64
|
-
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#create-a-to-do
|
65
|
-
def create_todo(todolist, content, options={})
|
66
|
-
post(todolist.todos_url, body: { content: content, **options }, override_path: true)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Complete a todo
|
70
|
-
#
|
71
|
-
# @example
|
72
|
-
# client.complete_todo(todo)
|
73
|
-
#
|
74
|
-
# @param todo [Resource] the todo to be marked as completed
|
75
|
-
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#complete-a-to-do
|
76
|
-
def complete_todo(todo)
|
77
|
-
post("#{todo.url}/completion", override_path: true)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|