camper 0.0.11 → 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.
@@ -1,97 +1,99 @@
1
1
  # frozen_string_literal: true
2
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 [PaginatedResponse<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
3
+ module Camper
4
+ class Client
5
+ # Defines methods related to people.
6
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md
7
+ module PeopleAPI
8
+ # Get all people visible to the current user
9
+ #
10
+ # @example
11
+ # client.people
12
+ #
13
+ # @return [PaginatedResponse<Resource>]
14
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#get-all-people
15
+ def people
16
+ get('/people')
17
+ end
17
18
 
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 [PaginatedResponse<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
19
+ # Get all active people on the project with the given ID
20
+ #
21
+ # @example
22
+ # client.people_in_project(10)
23
+ # @example
24
+ # client.people_in_project("20")
25
+ # @example
26
+ # client.people_in_project(my_project)
27
+ #
28
+ # @param project [Resource|Integer|String] A project resource or a project id
29
+ # @return [PaginatedResponse<Resource>]
30
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#get-people-on-a-project
31
+ def people_in_project(project)
32
+ id = project.respond_to?(:id) ? project.id : project
32
33
 
33
- get("/projects/#{id}/people")
34
- end
34
+ get("/projects/#{id}/people")
35
+ end
35
36
 
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?
37
+ # Allows granting new and existing people access to a project, and revoking access from existing people.
38
+ #
39
+ # @example
40
+ # client.update_access_in_project(10, { grant: [102, 127] })
41
+ # @example
42
+ # client.update_access_in_project("8634", { revoke: [300, 12527] })
43
+ # @example
44
+ # client.update_access_in_project(my_project, {
45
+ # create: [{
46
+ # name: "Victor Copper",
47
+ # email_address: "victor@hanchodesign.com"
48
+ # }]
49
+ # })
50
+ #
51
+ # @param project [Resource|Integer|String] A project resource or a project id
52
+ # @param options [Hash] options to update access, either grant, revoke or create new people
53
+ # @return [Resource]
54
+ # @raise [Error::InvalidParameter] if no option is specified
55
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#update-who-can-access-a-project
56
+ def update_access_in_project(project, options = {})
57
+ raise Camper::Error::InvalidParameter, 'options cannot be empty' if options.empty?
57
58
 
58
- id = project.respond_to?(:id) ? project.id : project
59
+ id = project.respond_to?(:id) ? project.id : project
59
60
 
60
- put("/projects/#{id}/people/users", body: { **options })
61
- end
61
+ put("/projects/#{id}/people/users", body: { **options })
62
+ end
62
63
 
63
- # Get all people on this Basecamp account who can be pinged
64
- #
65
- # @example
66
- # client.pingable_people
67
- #
68
- # @return [PaginatedResponse<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
64
+ # Get all people on this Basecamp account who can be pinged
65
+ #
66
+ # @example
67
+ # client.pingable_people
68
+ #
69
+ # @return [PaginatedResponse<Resource>]
70
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#get-pingable-people
71
+ def pingable_people
72
+ get('/circles/people')
73
+ end
73
74
 
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
75
+ # Get the profile for the user with the given ID
76
+ #
77
+ # @example
78
+ # client.person(234790)
79
+ #
80
+ # @param id [Integer|String] A user id
81
+ # @return [Resource]
82
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#get-person
83
+ def person(id)
84
+ get("/people/#{id}")
85
+ end
85
86
 
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')
87
+ # Get the current user's personal info.
88
+ #
89
+ # @example
90
+ # client.profile
91
+ #
92
+ # @return [Resource]
93
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#get-my-personal-info
94
+ def profile
95
+ get('/my/profile')
96
+ end
95
97
  end
96
98
  end
97
99
  end
@@ -1,120 +1,120 @@
1
1
  # frozen_string_literal: true
2
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 [PaginatedResponse<Project>]
16
- # @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md#get-all-projects
17
- def projects(options = {})
18
- get('/projects', query: 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?
3
+ module Camper
4
+ class Client
5
+ # Defines methods related to projects.
6
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md
7
+ module ProjectsAPI
8
+ # Get the projects visible to the current user
9
+ #
10
+ # @example
11
+ # client.projects
12
+ # @example
13
+ # client.projects(status: 'trashed')
14
+ #
15
+ # @param options [Hash] extra options to filter the list of todolist
16
+ # @return [PaginatedResponse<Project>]
17
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md#get-all-projects
18
+ def projects(options = {})
19
+ get('/projects', query: options)
20
+ end
34
21
 
35
- get("/projects/#{id}")
36
- end
22
+ # Get a project with a given id, granted they have access to it
23
+ #
24
+ # @example
25
+ # client.project(82564)
26
+ # @example
27
+ # client.project('7364183')
28
+ #
29
+ # @param id [Integet|String] id of the project to retrieve
30
+ # @return [Project]
31
+ # @raise [Error::InvalidParameter] if id is blank (nil or empty string)
32
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md#get-a-project
33
+ def project(id)
34
+ raise Error::InvalidParameter, id if id.blank?
37
35
 
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?
36
+ get("/projects/#{id}")
37
+ end
52
38
 
53
- post('/projects', body: { name: name, description: description })
54
- end
39
+ # Create a project
40
+ #
41
+ # @example
42
+ # client.create_project("Marketing Campaign")
43
+ # @example
44
+ # client.create_project('Better Marketing Campaign', "For Client: XYZ")
45
+ #
46
+ # @param name [String] name of the project to create
47
+ # @param description [String] description of the project
48
+ # @return [Project]
49
+ # @raise [Error::InvalidParameter] if name is blank (nil or empty string)
50
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md#create-a-project
51
+ def create_project(name, description = '')
52
+ raise Error::InvalidParameter, name if name.blank?
55
53
 
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'
54
+ post('/projects', body: { name: name, description: description })
77
55
  end
78
56
 
79
- id = project.respond_to?(:id) ? project.id : project
57
+ # Update a project
58
+ # description can be set to empty by passing an empty string
59
+ #
60
+ # @example
61
+ # client.update_project(12324, name: 'Retros')
62
+ # @example
63
+ # client.update_project('157432', description: 'A new description')
64
+ # @example
65
+ # client.update_project('157432', description: '')
66
+ # @example
67
+ # client.update_project(my_project, name: 'A new name', description: 'A new description')
68
+ #
69
+ # @param project [Integer|String|Project] either a project object or a project id
70
+ # @param name [String] optional new name of the project
71
+ # @param description [String] optinal new description of the project
72
+ # @return [Project]
73
+ # @raise [Error::InvalidParameter] if both name and description are blank (nil or empty strings)
74
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md#update-a-project
75
+ def update_project(project, name: '', description: nil)
76
+ # rubocop:disable Style/IfUnlessModifier:
77
+ if name.blank? && description.blank?
78
+ raise Error::InvalidParameter, 'name and description cannot both be blank'
79
+ end
80
80
 
81
- options = {}
82
- options[:name] = name unless name.blank?
83
- options[:description] = description unless description.nil?
81
+ # rubocop:enable Style/IfUnlessModifier
84
82
 
85
- put("/projects/#{id}", body: { **options })
86
- end
83
+ id = project.respond_to?(:id) ? project.id : project
87
84
 
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?
85
+ options = {}
86
+ options[:name] = name unless name.blank?
87
+ options[:description] = description unless description.nil?
102
88
 
103
- id = project.respond_to?(:id) ? project.id : project
89
+ put("/projects/#{id}", body: { **options })
90
+ end
104
91
 
105
- delete("/projects/#{id}")
106
- end
92
+ # Delete a project
93
+ #
94
+ # @example
95
+ # client.delete_project(12324)
96
+ # @example
97
+ # client.delete_project('157432')
98
+ # @example
99
+ # client.delete_project(my_project)
100
+ #
101
+ # @param project [Integer|String|Project] either a project object or a project id
102
+ # @raise [Error::InvalidParameter] if project param is blank
103
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md#trash-a-project
104
+ def delete_project(project)
105
+ raise Error::InvalidParameter, 'project cannot be blank' if project.blank?
107
106
 
108
- alias trash_project delete_project
107
+ id = project.respond_to?(:id) ? project.id : project
109
108
 
110
- def message_board(project)
111
- board = project.message_board
112
- get(board.url, override_path: true)
113
- end
109
+ delete("/projects/#{id}")
110
+ end
111
+
112
+ alias trash_project delete_project
114
113
 
115
- def todoset(project)
116
- todoset = project.todoset
117
- get(todoset.url, override_path: true)
114
+ def todoset(project)
115
+ todoset = project.todoset
116
+ get(todoset.url, override_path: true)
117
+ end
118
118
  end
119
119
  end
120
120
  end
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Camper::Client
4
- module ResourceAPI
5
- def resource(url)
6
- get(url, override_path: true)
3
+ module Camper
4
+ class Client
5
+ module ResourceAPI
6
+ def resource(url)
7
+ get(url, override_path: true)
8
+ end
7
9
  end
8
10
  end
9
11
  end
@@ -1,103 +1,95 @@
1
1
  # frozen_string_literal: true
2
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 [PaginatedResponse<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
3
+ module Camper
4
+ class Client
5
+ # Defines methods related to todolists.
6
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md
7
+ module TodolistsAPI
8
+ # Get the todolists associated with the todoset
9
+ #
10
+ # @example
11
+ # client.todolists(todoset)
12
+ # @example
13
+ # client.todolists(todoset, status: 'archived')
14
+ #
15
+ # @param todoset [Resource] the parent todoset resource
16
+ # @param options [Hash] extra options to filter the list of todolist
17
+ # @return [PaginatedResponse<Resource>]
18
+ # @raise [Error::InvalidParameter] if todolists_url field in todoset param
19
+ # is not a valid basecamp url
20
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md#get-to-do-lists
21
+ def todolists(todoset, options = {})
22
+ get(todoset.todolists_url, query: options, override_path: true)
23
+ end
22
24
 
23
- raise Camper::Error::InvalidParameter, todoset unless Camper::UrlUtils.basecamp_url?(url)
25
+ # Get a todolist with a given id
26
+ #
27
+ # @example
28
+ # client.todolist(todoset, '2345')
29
+ #
30
+ # @param todoset [Resource] the parent todoset resource
31
+ # @param id [Integer, String] the id of the todolist to get
32
+ # @return [Resource]
33
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md#get-a-to-do-list
34
+ def todolist(todoset, id)
35
+ get("/buckets/#{todoset.bucket.id}/todolists/#{id}")
36
+ end
24
37
 
25
- get(url, query: options, 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
38
+ # Create a todolist within the given todoset
39
+ #
40
+ # @example
41
+ # client.create_todolist(todoset, 'Launch', "<div><em>Finish it!</em></div>")
42
+ #
43
+ # @param todoset [Resource] the parent todoset resource
44
+ # @param name [String] the name of the new todolist
45
+ # @param description [String] an optional description for the todolist
46
+ # @return [Resource]
47
+ # @raise [Error::InvalidParameter] if todolists_url field in todoset param
48
+ # is not a valid basecamp url
49
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md#create-a-to-do-list
50
+ def create_todolist(todoset, name, description = '')
51
+ body = { name: name, description: description }
40
52
 
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
53
+ post(todoset.todolists_url, body: body, override_path: true)
54
+ end
55
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
56
+ # Update a todolist to change name and description
57
+ #
58
+ # @example
59
+ # client.update_todolist(todolist, 'Launch')
60
+ # @example
61
+ # client.update_todolist(todolist, 'Launch', "<div><em>Finish it!</em></div>")
62
+ # @example
63
+ # client.update_todolist(todolist, 'Launch', '')
64
+ #
65
+ # @param todolist [Resource] the todolist resource to update
66
+ # @param name [String] the new name of the todolist
67
+ # @param description [String] a new optional description for the todolist. If not specified,
68
+ # it will be set to the current description value
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 = nil)
74
+ body = { name: name }
75
+ body[:description] = description.nil? ? todolist.description : description
60
76
 
61
- # Update a todolist to change name and description
62
- #
63
- # @example
64
- # client.update_todolist(todolist, 'Launch')
65
- # @example
66
- # client.update_todolist(todolist, 'Launch', "<div><em>Finish it!</em></div>")
67
- # @example
68
- # client.update_todolist(todolist, 'Launch', '')
69
- #
70
- # @param todolist [Resource] the todolist resource to update
71
- # @param name [String] the new name of the todolist
72
- # @param description [String] a new optional description for the todolist. If not specified,
73
- # it will be set to the current description value
74
- # @return [Resource]
75
- # @raise [Error::InvalidParameter] if url field in todolist param
76
- # is not a valid basecamp url
77
- # @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md#update-a-to-do-list
78
- def update_todolist(todolist, name, description = nil)
79
- url = todolist.url
80
-
81
- raise Camper::Error::InvalidParameter, todolist unless Camper::UrlUtils.basecamp_url?(url)
82
-
83
- body = { name: name }
84
- body[:description] = description.nil? ? todolist.description : description
85
-
86
- put(url, body: body, override_path: true)
87
- end
77
+ put(todolist.url, body: body, override_path: true)
78
+ end
88
79
 
89
- # Trash a todolist
90
- # it calls the trash_recording endpoint under the hood
91
- #
92
- # @example
93
- # client.trash_todolist(todolist)
94
- #
95
- # @param todolist [Resource] the todolist to be trashed
96
- # @raise [Error::InvalidParameter] if the type field in todolist param
97
- # is not an allowed type in the recording API
98
- # @see https://github.com/basecamp/bc3-api/blob/master/sections/recordings.md#trash-a-recording
99
- def trash_todolist(todolist)
100
- trash_recording(todolist)
80
+ # Trash a todolist
81
+ # it calls the trash_recording endpoint under the hood
82
+ #
83
+ # @example
84
+ # client.trash_todolist(todolist)
85
+ #
86
+ # @param todolist [Resource] the todolist to be trashed
87
+ # @raise [Error::InvalidParameter] if the type field in todolist param
88
+ # is not an allowed type in the recording API
89
+ # @see https://github.com/basecamp/bc3-api/blob/master/sections/recordings.md#trash-a-recording
90
+ def trash_todolist(todolist)
91
+ trash_recording(todolist)
92
+ end
101
93
  end
102
94
  end
103
95
  end