camper 0.0.5 → 0.0.10
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 +5 -1
- data/.yardopts +4 -0
- data/CHANGELOG.md +44 -1
- data/Gemfile.lock +14 -11
- data/README.md +53 -22
- data/camper.gemspec +2 -0
- data/examples/comments.rb +1 -1
- data/examples/create_and_complete_todo.rb +24 -0
- data/examples/people.rb +11 -0
- data/examples/projects.rb +12 -0
- data/examples/todolists.rb +32 -0
- data/examples/todos.rb +8 -5
- data/lib/camper.rb +1 -0
- data/lib/camper/api/{comment.rb → comments.rb} +5 -3
- data/lib/camper/api/{message.rb → messages.rb} +1 -1
- data/lib/camper/api/people.rb +97 -0
- data/lib/camper/api/projects.rb +120 -0
- data/lib/camper/api/resource.rb +1 -3
- data/lib/camper/api/todolists.rb +81 -0
- data/lib/camper/api/todos.rb +133 -0
- data/lib/camper/authorization.rb +1 -1
- data/lib/camper/client.rb +37 -33
- data/lib/camper/configuration.rb +4 -6
- data/lib/camper/core_extensions/object.rb +156 -0
- data/lib/camper/error.rb +15 -4
- data/lib/camper/pagination_data.rb +0 -3
- data/lib/camper/request.rb +49 -20
- data/lib/camper/resource.rb +0 -2
- data/lib/camper/url_utils.rb +26 -0
- data/lib/camper/version.rb +1 -1
- metadata +44 -7
- data/lib/camper/api/project.rb +0 -20
- data/lib/camper/api/todo.rb +0 -14
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Camper::Client
|
4
|
+
# Defines methods related to people.
|
5
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md
|
6
|
+
module PeopleAPI
|
7
|
+
# Get all people visible to the current user
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# client.people
|
11
|
+
#
|
12
|
+
# @return [Array<Resource>]
|
13
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#get-all-people
|
14
|
+
def people
|
15
|
+
get('/people')
|
16
|
+
end
|
17
|
+
|
18
|
+
# Get all active people on the project with the given ID
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# client.people_in_project(10)
|
22
|
+
# @example
|
23
|
+
# client.people_in_project("20")
|
24
|
+
# @example
|
25
|
+
# client.people_in_project(my_project)
|
26
|
+
#
|
27
|
+
# @param project [Resource|Integer|String] A project resource or a project id
|
28
|
+
# @return [Array<Resource>]
|
29
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#get-people-on-a-project
|
30
|
+
def people_in_project(project)
|
31
|
+
id = project.respond_to?(:id) ? project.id : project
|
32
|
+
|
33
|
+
get("/projects/#{id}/people")
|
34
|
+
end
|
35
|
+
|
36
|
+
# Allows granting new and existing people access to a project, and revoking access from existing people.
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# client.update_access_in_project(10, { grant: [102, 127] })
|
40
|
+
# @example
|
41
|
+
# client.update_access_in_project("8634", { revoke: [300, 12527] })
|
42
|
+
# @example
|
43
|
+
# client.update_access_in_project(my_project, {
|
44
|
+
# create: [{
|
45
|
+
# name: "Victor Copper",
|
46
|
+
# email_address: "victor@hanchodesign.com"
|
47
|
+
# }]
|
48
|
+
# })
|
49
|
+
#
|
50
|
+
# @param project [Resource|Integer|String] A project resource or a project id
|
51
|
+
# @param options [Hash] options to update access, either grant, revoke or create new people
|
52
|
+
# @return [Resource]
|
53
|
+
# @raise [Error::InvalidParameter] if no option is specified
|
54
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#update-who-can-access-a-project
|
55
|
+
def update_access_in_project(project, options = {})
|
56
|
+
raise Camper::Error::InvalidParameter, 'options cannot be empty' if options.empty?
|
57
|
+
|
58
|
+
id = project.respond_to?(:id) ? project.id : project
|
59
|
+
|
60
|
+
put("/projects/#{id}/people/users", body: { **options })
|
61
|
+
end
|
62
|
+
|
63
|
+
# Get all people on this Basecamp account who can be pinged
|
64
|
+
#
|
65
|
+
# @example
|
66
|
+
# client.pingable_people
|
67
|
+
#
|
68
|
+
# @return [Array<Resource>]
|
69
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#get-pingable-people
|
70
|
+
def pingable_people
|
71
|
+
get('/circles/people')
|
72
|
+
end
|
73
|
+
|
74
|
+
# Get the profile for the user with the given ID
|
75
|
+
#
|
76
|
+
# @example
|
77
|
+
# client.person(234790)
|
78
|
+
#
|
79
|
+
# @param id [Integer|String] A user id
|
80
|
+
# @return [Resource]
|
81
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#get-person
|
82
|
+
def person(id)
|
83
|
+
get("/people/#{id}")
|
84
|
+
end
|
85
|
+
|
86
|
+
# Get the current user's personal info.
|
87
|
+
#
|
88
|
+
# @example
|
89
|
+
# client.profile
|
90
|
+
#
|
91
|
+
# @return [Resource]
|
92
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#get-my-personal-info
|
93
|
+
def profile
|
94
|
+
get('/my/profile')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Camper::Client
|
4
|
+
# Defines methods related to projects.
|
5
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md
|
6
|
+
module ProjectsAPI
|
7
|
+
# Get the projects visible to the current user
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# client.projects
|
11
|
+
# @example
|
12
|
+
# client.projects(status: 'trashed')
|
13
|
+
#
|
14
|
+
# @param options [Hash] extra options to filter the list of todolist
|
15
|
+
# @return [Array<Project>]
|
16
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md#get-all-projects
|
17
|
+
def projects(options = {})
|
18
|
+
get('/projects', options)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get a project with a given id, granted they have access to it
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# client.project(82564)
|
25
|
+
# @example
|
26
|
+
# client.project('7364183')
|
27
|
+
#
|
28
|
+
# @param id [Integet|String] id of the project to retrieve
|
29
|
+
# @return [Project]
|
30
|
+
# @raise [Error::InvalidParameter] if id is blank (nil or empty string)
|
31
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md#get-a-project
|
32
|
+
def project(id)
|
33
|
+
raise Camper::Error::InvalidParameter, id if id.blank?
|
34
|
+
|
35
|
+
get("/projects/#{id}")
|
36
|
+
end
|
37
|
+
|
38
|
+
# Create a project
|
39
|
+
#
|
40
|
+
# @example
|
41
|
+
# client.create_project("Marketing Campaign")
|
42
|
+
# @example
|
43
|
+
# client.create_project('Better Marketing Campaign', "For Client: XYZ")
|
44
|
+
#
|
45
|
+
# @param name [String] name of the project to create
|
46
|
+
# @param description [String] description of the project
|
47
|
+
# @return [Project]
|
48
|
+
# @raise [Error::InvalidParameter] if name is blank (nil or empty string)
|
49
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md#create-a-project
|
50
|
+
def create_project(name, description = '')
|
51
|
+
raise Camper::Error::InvalidParameter, name if name.blank?
|
52
|
+
|
53
|
+
post('/projects', body: { name: name, description: description })
|
54
|
+
end
|
55
|
+
|
56
|
+
# Update a project
|
57
|
+
# description can be set to empty by passing an empty string
|
58
|
+
#
|
59
|
+
# @example
|
60
|
+
# client.update_project(12324, name: 'Retros')
|
61
|
+
# @example
|
62
|
+
# client.update_project('157432', description: 'A new description')
|
63
|
+
# @example
|
64
|
+
# client.update_project('157432', description: '')
|
65
|
+
# @example
|
66
|
+
# client.update_project(my_project, name: 'A new name', description: 'A new description')
|
67
|
+
#
|
68
|
+
# @param project [Integer|String|Project] either a project object or a project id
|
69
|
+
# @param name [String] optional new name of the project
|
70
|
+
# @param description [String] optinal new description of the project
|
71
|
+
# @return [Project]
|
72
|
+
# @raise [Error::InvalidParameter] if both name and description are blank (nil or empty strings)
|
73
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md#update-a-project
|
74
|
+
def update_project(project, name: '', description: nil)
|
75
|
+
if name.blank? && description.blank?
|
76
|
+
raise Camper::Error::InvalidParameter, 'name and description cannot both be blank'
|
77
|
+
end
|
78
|
+
|
79
|
+
id = project.respond_to?(:id) ? project.id : project
|
80
|
+
|
81
|
+
options = {}
|
82
|
+
options[:name] = name unless name.blank?
|
83
|
+
options[:description] = description unless description.nil?
|
84
|
+
|
85
|
+
put("/projects/#{id}", body: { **options })
|
86
|
+
end
|
87
|
+
|
88
|
+
# Delete a project
|
89
|
+
#
|
90
|
+
# @example
|
91
|
+
# client.delete_project(12324)
|
92
|
+
# @example
|
93
|
+
# client.delete_project('157432')
|
94
|
+
# @example
|
95
|
+
# client.delete_project(my_project)
|
96
|
+
#
|
97
|
+
# @param project [Integer|String|Project] either a project object or a project id
|
98
|
+
# @raise [Error::InvalidParameter] if project param is blank
|
99
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md#trash-a-project
|
100
|
+
def delete_project(project)
|
101
|
+
raise Camper::Error::InvalidParameter, 'project cannot be blank' if project.blank?
|
102
|
+
|
103
|
+
id = project.respond_to?(:id) ? project.id : project
|
104
|
+
|
105
|
+
delete("/projects/#{id}")
|
106
|
+
end
|
107
|
+
|
108
|
+
alias trash_project delete_project
|
109
|
+
|
110
|
+
def message_board(project)
|
111
|
+
board = project.message_board
|
112
|
+
get(board.url, override_path: true)
|
113
|
+
end
|
114
|
+
|
115
|
+
def todoset(project)
|
116
|
+
todoset = project.todoset
|
117
|
+
get(todoset.url, override_path: true)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/lib/camper/api/resource.rb
CHANGED
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Camper::Client
|
4
|
+
# Defines methods related to todolists.
|
5
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md
|
6
|
+
module TodolistsAPI
|
7
|
+
# Get the todolists associated with the todoset
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# client.todolists(todoset)
|
11
|
+
# @example
|
12
|
+
# client.todolists(todoset, status: 'archived')
|
13
|
+
#
|
14
|
+
# @param todoset [Resource] the parent todoset resource
|
15
|
+
# @param options [Hash] extra options to filter the list of todolist
|
16
|
+
# @return [Array<Resource>]
|
17
|
+
# @raise [Error::InvalidParameter] if todolists_url field in todoset param
|
18
|
+
# is not a valid basecamp url
|
19
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md#get-to-do-lists
|
20
|
+
def todolists(todoset, options = {})
|
21
|
+
url = todoset.todolists_url
|
22
|
+
|
23
|
+
raise Camper::Error::InvalidParameter, todoset unless Camper::UrlUtils.basecamp_url?(url)
|
24
|
+
|
25
|
+
get(url, options.merge(override_path: true))
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get a todolist with a given id
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# client.todolist(todoset, '2345')
|
32
|
+
#
|
33
|
+
# @param todoset [Resource] the parent todoset resource
|
34
|
+
# @param id [Integer, String] the id of the todolist to get
|
35
|
+
# @return [Resource]
|
36
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md#get-a-to-do-list
|
37
|
+
def todolist(todoset, id)
|
38
|
+
get("/buckets/#{todoset.bucket.id}/todolists/#{id}")
|
39
|
+
end
|
40
|
+
|
41
|
+
# Create a todolist within the given todoset
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
# client.create_todolist(todoset, 'Launch', "<div><em>Finish it!</em></div>")
|
45
|
+
#
|
46
|
+
# @param todoset [Resource] the parent todoset resource
|
47
|
+
# @param name [String] the name of the new todolist
|
48
|
+
# @param description [String] an optional description for the todolist
|
49
|
+
# @return [Resource]
|
50
|
+
# @raise [Error::InvalidParameter] if todolists_url field in todoset param
|
51
|
+
# is not a valid basecamp url
|
52
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md#create-a-to-do-list
|
53
|
+
def create_todolist(todoset, name, description = '')
|
54
|
+
url = todoset.todolists_url
|
55
|
+
|
56
|
+
raise Camper::Error::InvalidParameter, todoset unless Camper::UrlUtils.basecamp_url?(url)
|
57
|
+
|
58
|
+
post(url, body: { name: name, description: description }, override_path: true)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Update a todolist to change name and description
|
62
|
+
#
|
63
|
+
# @example
|
64
|
+
# client.update_todolist(todolist, 'Launch', "<div><em>Finish it!</em></div>")
|
65
|
+
#
|
66
|
+
# @param todolist [Resource] the todolist resource to update
|
67
|
+
# @param name [String] the new name of the todolist
|
68
|
+
# @param description [String] a new optional description for the todolist
|
69
|
+
# @return [Resource]
|
70
|
+
# @raise [Error::InvalidParameter] if url field in todolist param
|
71
|
+
# is not a valid basecamp url
|
72
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md#update-a-to-do-list
|
73
|
+
def update_todolist(todolist, name, description = '')
|
74
|
+
url = todolist.url
|
75
|
+
|
76
|
+
raise Camper::Error::InvalidParameter, todolist unless Camper::UrlUtils.basecamp_url?(url)
|
77
|
+
|
78
|
+
put(url, body: { name: name, description: description }, override_path: true)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# frozen_string_literal: true
|
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
|
+
# Get the todos in a todolist
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# client.todos(todolist)
|
11
|
+
# @example
|
12
|
+
# client.todos(todolist, completed: true)
|
13
|
+
#
|
14
|
+
# @param todolist [Resource] the parent todoset resource
|
15
|
+
# @param options [Hash] options to filter the list of todos
|
16
|
+
# @return [Resource]
|
17
|
+
# @raise [Error::InvalidParameter] if todos_url field in todolist param
|
18
|
+
# is not a valid basecamp url
|
19
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#get-to-dos
|
20
|
+
def todos(todolist, options = {})
|
21
|
+
url = todolist.todos_url
|
22
|
+
|
23
|
+
raise Camper::Error::InvalidParameter, todolist unless Camper::UrlUtils.basecamp_url?(url)
|
24
|
+
|
25
|
+
get(url, options.merge(override_path: true))
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get a todo with a given id using a particular parent resource.
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# client.todo(my_project, '10')
|
32
|
+
# @example
|
33
|
+
# client.todo(new_todolist, 134)
|
34
|
+
# @example
|
35
|
+
# client.todo(67543, '2440')
|
36
|
+
#
|
37
|
+
# @param parent [Integer|String|Project|Resource] can be either a project id, a project or a todolist resource
|
38
|
+
# @param id [Integer|String] id of the todo
|
39
|
+
# @return [Resource]
|
40
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#get-a-to-do
|
41
|
+
def todo(parent, id)
|
42
|
+
bucket_id = parent
|
43
|
+
|
44
|
+
if parent.is_a? Camper::Project
|
45
|
+
bucket_id = parent.id
|
46
|
+
elsif parent.respond_to?(:type)
|
47
|
+
bucket_id = parent.bucket.id
|
48
|
+
end
|
49
|
+
|
50
|
+
get("/buckets/#{bucket_id}/todos/#{id}")
|
51
|
+
end
|
52
|
+
|
53
|
+
# Create a todo within a todolist
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# client.create_todo(todolist, 'First Todo')
|
57
|
+
# @example
|
58
|
+
# client.create_todo(
|
59
|
+
# todolist,
|
60
|
+
# 'Program it',
|
61
|
+
# description: "<div><em>Try that new language!</em></div>, due_on: "2016-05-01"
|
62
|
+
# )
|
63
|
+
#
|
64
|
+
# @param todolist [Resource] the todolist where the todo is going to be created
|
65
|
+
# @param content [String] what the to-do is for
|
66
|
+
# @param options [Hash] extra configuration for the todo such as due_date and description
|
67
|
+
# @return [Resource]
|
68
|
+
# @raise [Error::InvalidParameter] if todos_url field in todolist param
|
69
|
+
# is not a valid basecamp url
|
70
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#create-a-to-do
|
71
|
+
def create_todo(todolist, content, options = {})
|
72
|
+
url = todolist.todos_url
|
73
|
+
|
74
|
+
raise Camper::Error::InvalidParameter, todolist unless Camper::UrlUtils.basecamp_url?(url)
|
75
|
+
|
76
|
+
post(url, body: { content: content, **options }, override_path: true)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Complete a todo
|
80
|
+
#
|
81
|
+
# @example
|
82
|
+
# client.complete_todo(todo)
|
83
|
+
#
|
84
|
+
# @param todo [Resource] the todo to be marked as completed
|
85
|
+
# @raise [Error::InvalidParameter] if url field in todo param
|
86
|
+
# is not a valid basecamp url
|
87
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#complete-a-to-do
|
88
|
+
def complete_todo(todo)
|
89
|
+
url = todo.url
|
90
|
+
|
91
|
+
raise Camper::Error::InvalidParameter, todo unless Camper::UrlUtils.basecamp_url?(url)
|
92
|
+
|
93
|
+
post("#{url}/completion", override_path: true)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Uncomplete a todo
|
97
|
+
#
|
98
|
+
# @example
|
99
|
+
# client.uncomplete_todo(todo)
|
100
|
+
#
|
101
|
+
# @param todo [Resource] the todo to be marked as uncompleted
|
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#uncomplete-a-to-do
|
105
|
+
def uncomplete_todo(todo)
|
106
|
+
url = todo.url
|
107
|
+
|
108
|
+
raise Camper::Error::InvalidParameter, todo unless Camper::UrlUtils.basecamp_url?(url)
|
109
|
+
|
110
|
+
delete("#{url}/completion", override_path: true)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Reposition a todo
|
114
|
+
#
|
115
|
+
# @example
|
116
|
+
# client.uncomplete_todo(todo)
|
117
|
+
#
|
118
|
+
# @param todo [Resource] the todo to be repositioned
|
119
|
+
# @param position [Integer|String] new position for the todo
|
120
|
+
# @raise [Error::InvalidParameter] if url field in todo param
|
121
|
+
# is not a valid basecamp url
|
122
|
+
# @raise [Error::InvalidParameter] if position param is less than 1
|
123
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#reposition-a-to-do
|
124
|
+
def reposition_todo(todo, position)
|
125
|
+
url = todo.url
|
126
|
+
raise Camper::Error::InvalidParameter, todo unless Camper::UrlUtils.basecamp_url?(url)
|
127
|
+
|
128
|
+
raise Camper::Error::InvalidParameter, position if position.to_i < 1
|
129
|
+
|
130
|
+
put("#{url}/position", position: position, override_path: true)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|