camper 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +8 -10
- data/README.md +7 -6
- data/examples/people.rb +10 -0
- data/examples/todolists.rb +32 -0
- data/examples/todos.rb +8 -5
- data/lib/camper.rb +1 -0
- data/lib/camper/api/people.rb +3 -3
- data/lib/camper/api/todolists.rb +81 -0
- data/lib/camper/api/todos.rb +85 -31
- data/lib/camper/client.rb +1 -0
- data/lib/camper/error.rb +2 -0
- data/lib/camper/request.rb +1 -12
- data/lib/camper/url_utils.rb +26 -0
- data/lib/camper/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 702097b0560277ca7116dea4caed2e50e34f6d6732ba0be390515931220ef24b
|
4
|
+
data.tar.gz: 402cc359f4b7013691c36927e26502efe14a52b222471c8e5513a1d2b8e4c106
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8681cda10f1bc5acc17a407d53a517bac0763758df16773952c8c84b9e7b380c5b18c7254a0d39d09dda70d505732a0c0f515d4c863adb4bab0b8471d66ef383
|
7
|
+
data.tar.gz: a43b2d372e1f539f68ad8ec4bfd212353305da29a72f1bb82382609e0ce2ea237b7b457b92ed0d1d54c300a7d2fa4a8a5077fd0e5b84b1d7b982bb6bd3ccf5a4
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,16 @@
|
|
4
4
|
|
5
5
|
**Implemented enhancements:**
|
6
6
|
|
7
|
+
- Split todos and todolists APIs [\#47](https://github.com/renehernandez/camper/pull/47)
|
8
|
+
|
9
|
+
**Merged pull requests:**
|
10
|
+
|
11
|
+
- Bump rubocop from 0.92.0 to 1.0.0 [\#44](https://github.com/renehernandez/camper/pull/44)
|
12
|
+
|
13
|
+
## [v0.0.8](https://github.com/renehernandez/camper/tree/v0.0.8) (2020-10-27)
|
14
|
+
|
15
|
+
**Implemented enhancements:**
|
16
|
+
|
7
17
|
- Add people API [\#46](https://github.com/renehernandez/camper/pull/46)
|
8
18
|
- Raise error if resource can't be commented [\#45](https://github.com/renehernandez/camper/pull/45)
|
9
19
|
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
camper (0.0.
|
4
|
+
camper (0.0.8)
|
5
5
|
httparty (~> 0.18)
|
6
6
|
rack-oauth2 (~> 1.14)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (6.0.3.
|
11
|
+
activesupport (6.0.3.4)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 0.7, < 2)
|
14
14
|
minitest (~> 5.1)
|
@@ -38,7 +38,7 @@ GEM
|
|
38
38
|
minitest (5.14.2)
|
39
39
|
multi_xml (0.6.0)
|
40
40
|
parallel (1.19.2)
|
41
|
-
parser (2.7.
|
41
|
+
parser (2.7.2.0)
|
42
42
|
ast (~> 2.4.1)
|
43
43
|
pry (0.13.1)
|
44
44
|
coderay (~> 1.1)
|
@@ -52,7 +52,7 @@ GEM
|
|
52
52
|
rack (>= 2.1.0)
|
53
53
|
rainbow (3.0.0)
|
54
54
|
rake (13.0.1)
|
55
|
-
regexp_parser (1.8.
|
55
|
+
regexp_parser (1.8.2)
|
56
56
|
rexml (3.2.4)
|
57
57
|
rspec (3.9.0)
|
58
58
|
rspec-core (~> 3.9.0)
|
@@ -67,23 +67,21 @@ GEM
|
|
67
67
|
diff-lcs (>= 1.2.0, < 2.0)
|
68
68
|
rspec-support (~> 3.9.0)
|
69
69
|
rspec-support (3.9.3)
|
70
|
-
rubocop (0.
|
70
|
+
rubocop (1.0.0)
|
71
71
|
parallel (~> 1.10)
|
72
72
|
parser (>= 2.7.1.5)
|
73
73
|
rainbow (>= 2.2.2, < 4.0)
|
74
|
-
regexp_parser (>= 1.
|
74
|
+
regexp_parser (>= 1.8)
|
75
75
|
rexml
|
76
|
-
rubocop-ast (>= 0.
|
76
|
+
rubocop-ast (>= 0.6.0)
|
77
77
|
ruby-progressbar (~> 1.7)
|
78
78
|
unicode-display_width (>= 1.4.0, < 2.0)
|
79
|
-
rubocop-ast (0.
|
79
|
+
rubocop-ast (1.0.0)
|
80
80
|
parser (>= 2.7.1.5)
|
81
|
-
strscan (>= 1.0.0)
|
82
81
|
rubocop-performance (1.8.1)
|
83
82
|
rubocop (>= 0.87.0)
|
84
83
|
rubocop-ast (>= 0.4.0)
|
85
84
|
ruby-progressbar (1.10.1)
|
86
|
-
strscan (1.0.3)
|
87
85
|
thread_safe (0.3.6)
|
88
86
|
tzinfo (1.2.7)
|
89
87
|
thread_safe (~> 0.1)
|
data/README.md
CHANGED
@@ -24,17 +24,18 @@ Or install it yourself as:
|
|
24
24
|
$ gem install camper
|
25
25
|
```
|
26
26
|
|
27
|
-
##
|
27
|
+
## Status of API endpoints
|
28
28
|
|
29
29
|
The up-to-date list of Basecamp API endpoints can be found at [here](https://github.com/basecamp/bc3-api#api-endpoints).
|
30
30
|
|
31
31
|
Currently, Camper supports the following endpoints:
|
32
32
|
|
33
|
-
* [Comments](https://github.com/basecamp/bc3-api/blob/master/sections/comments.md): Implementation at [comments.rb](
|
34
|
-
* [Messages](https://github.com/basecamp/bc3-api/blob/master/sections/messages.md): Implementation at [messages.rb](
|
35
|
-
* [People](https://github.com/basecamp/bc3-api/blob/master/sections/people.md): Implementation at [people.rb](
|
36
|
-
* [Projects](https://github.com/basecamp/bc3-api/blob/master/sections/projects.md): Implementation at [projects.rb](
|
37
|
-
* [To-
|
33
|
+
* [Comments](https://github.com/basecamp/bc3-api/blob/master/sections/comments.md): Implementation at [comments.rb](https://github.com/renehernandez/camper/blob/main/lib/camper/api/comments.rb) (Partial)
|
34
|
+
* [Messages](https://github.com/basecamp/bc3-api/blob/master/sections/messages.md): Implementation at [messages.rb](https://github.com/renehernandez/camper/blob/main/lib/camper/api/messages.rb) (Partial)
|
35
|
+
* [People](https://github.com/basecamp/bc3-api/blob/master/sections/people.md): Implementation at [people.rb](https://github.com/renehernandez/camper/blob/main/lib/camper/api/people.rb) (Complete)
|
36
|
+
* [Projects](https://github.com/basecamp/bc3-api/blob/master/sections/projects.md): Implementation at [projects.rb](https://github.com/renehernandez/camper/blob/main/lib/camper/api/projects.rb) (Partial)
|
37
|
+
* [To-do list](https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md): Implementation at [todolists.rb](https://github.com/renehernandez/camper/blob/main/lib/camper/api/todolists.rb) (Almost complete, only missing todolist trashing)
|
38
|
+
* [To-dos](https://github.com/basecamp/bc3-api/blob/master/sections/todos.md): Implementation at [todos.rb](https://github.com/renehernandez/camper/blob/main/lib/camper/api/todos.rb) (Almost complete, only missing todo trashing)
|
38
39
|
|
39
40
|
## Usage
|
40
41
|
|
data/examples/people.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'camper'
|
4
|
+
|
5
|
+
client = Camper.client
|
6
|
+
|
7
|
+
projects = client.projects
|
8
|
+
|
9
|
+
projects.auto_paginate do |p|
|
10
|
+
puts "Project: #{p.name}"
|
11
|
+
|
12
|
+
todoset = client.todoset(p)
|
13
|
+
|
14
|
+
puts "Ratio of completed Todos in Todoset: #{todoset.completed_ratio}"
|
15
|
+
|
16
|
+
client.todolists(todoset).auto_paginate(5) do |list|
|
17
|
+
puts "Todolist: #{list.title}"
|
18
|
+
|
19
|
+
client.todos(list).auto_paginate do |todo|
|
20
|
+
puts "Todo: #{todo.title}"
|
21
|
+
puts "Get Todo using project id: #{client.todo(p.id, todo.id).title}"
|
22
|
+
puts "Get Todo using project resource: #{client.todo(p, todo.id).title}"
|
23
|
+
puts "Get Todo using todolist resource: #{client.todo(list, todo.id).title}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
client.todolists(p)
|
29
|
+
rescue Camper::Error::InvalidParameter
|
30
|
+
puts 'Cannot use a project p to get the todolists'
|
31
|
+
end
|
32
|
+
end
|
data/examples/todos.rb
CHANGED
@@ -11,17 +11,20 @@ end
|
|
11
11
|
projects = client.projects
|
12
12
|
|
13
13
|
projects.auto_paginate do |p|
|
14
|
-
puts "Project: #{p.
|
15
|
-
|
16
|
-
puts "Todo set: #{p.todoset.inspect}"
|
14
|
+
puts "Project: #{p.name}"
|
17
15
|
|
18
16
|
todoset = client.todoset(p)
|
19
17
|
|
18
|
+
puts "Ratio of completed Todos in Todoset: #{todoset.completed_ratio}"
|
19
|
+
|
20
20
|
client.todolists(todoset).auto_paginate(5) do |list|
|
21
21
|
puts "Todolist: #{list.title}"
|
22
22
|
|
23
|
-
client.todos(list).auto_paginate do |todo|
|
24
|
-
puts todo.
|
23
|
+
client.todos(list).auto_paginate(1) do |todo|
|
24
|
+
puts "Todo: #{todo.title}"
|
25
|
+
puts "Get Todo using project id: #{client.todo(p.id, todo.id).title}"
|
26
|
+
puts "Get Todo using project resource: #{client.todo(p, todo.id).title}"
|
27
|
+
puts "Get Todo using todolist resource: #{client.todo(list, todo.id).title}"
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
data/lib/camper.rb
CHANGED
data/lib/camper/api/people.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
class Camper::Client
|
4
4
|
# Defines methods related to people.
|
5
|
-
# @see
|
5
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md
|
6
6
|
module PeopleAPI
|
7
7
|
# Get all people visible to the current user
|
8
8
|
#
|
@@ -50,10 +50,10 @@ class Camper::Client
|
|
50
50
|
# @param project [Resource|Integer|String] A project resource or a project id
|
51
51
|
# @param options [Hash] options to update access, either grant, revoke or create new people
|
52
52
|
# @return [Resource]
|
53
|
-
# @raise [Error::
|
53
|
+
# @raise [Error::InvalidParameter] if no option is specified
|
54
54
|
# @see https://github.com/basecamp/bc3-api/blob/master/sections/people.md#update-who-can-access-a-project
|
55
55
|
def update_access_in_project(project, options = {})
|
56
|
-
raise
|
56
|
+
raise Camper::Error::InvalidParameter, 'options cannot be empty' if options.empty?
|
57
57
|
|
58
58
|
id = project.respond_to?(:id) ? project.id : project
|
59
59
|
|
@@ -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
|
data/lib/camper/api/todos.rb
CHANGED
@@ -1,35 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Camper::Client
|
4
|
+
# Defines methods related to todos.
|
5
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md
|
4
6
|
module TodosAPI
|
5
|
-
# Get the todolists associated with the todoset
|
6
|
-
#
|
7
|
-
# @example
|
8
|
-
# client.todolists(todoset)
|
9
|
-
# @example
|
10
|
-
# client.todolists(todoset, status: 'archived')
|
11
|
-
#
|
12
|
-
# @param todoset [Resource] the parent todoset resource
|
13
|
-
# @param options [Hash] extra options to filter the list of todolist
|
14
|
-
# @return [Array<Resource>]
|
15
|
-
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md#get-to-do-lists
|
16
|
-
def todolists(todoset, options = {})
|
17
|
-
get(todoset.todolists_url, options.merge(override_path: true))
|
18
|
-
end
|
19
|
-
|
20
|
-
# Get a todolist with a given id
|
21
|
-
#
|
22
|
-
# @example
|
23
|
-
# client.todolist(todoset, '2345')
|
24
|
-
#
|
25
|
-
# @param todoset [Resource] the parent todoset resource
|
26
|
-
# @param id [Integer, String] the id of the todolist to get
|
27
|
-
# @return [Resource]
|
28
|
-
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todolists.md#get-a-to-do-list
|
29
|
-
def todolist(todoset, id)
|
30
|
-
get("/buckets/#{todoset.bucket.id}/todolists/#{id}")
|
31
|
-
end
|
32
|
-
|
33
7
|
# Get the todos in a todolist
|
34
8
|
#
|
35
9
|
# @example
|
@@ -40,9 +14,40 @@ class Camper::Client
|
|
40
14
|
# @param todolist [Resource] the parent todoset resource
|
41
15
|
# @param options [Hash] options to filter the list of todos
|
42
16
|
# @return [Resource]
|
17
|
+
# @raise [Error::InvalidParameter] if todos_url field in todolist param
|
18
|
+
# is not a valid basecamp url
|
43
19
|
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#get-to-dos
|
44
20
|
def todos(todolist, options = {})
|
45
|
-
|
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}")
|
46
51
|
end
|
47
52
|
|
48
53
|
# Create a todo within a todolist
|
@@ -60,9 +65,15 @@ class Camper::Client
|
|
60
65
|
# @param content [String] what the to-do is for
|
61
66
|
# @param options [Hash] extra configuration for the todo such as due_date and description
|
62
67
|
# @return [Resource]
|
68
|
+
# @raise [Error::InvalidParameter] if todos_url field in todolist param
|
69
|
+
# is not a valid basecamp url
|
63
70
|
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#create-a-to-do
|
64
71
|
def create_todo(todolist, content, options = {})
|
65
|
-
|
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)
|
66
77
|
end
|
67
78
|
|
68
79
|
# Complete a todo
|
@@ -71,9 +82,52 @@ class Camper::Client
|
|
71
82
|
# client.complete_todo(todo)
|
72
83
|
#
|
73
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
|
74
87
|
# @see https://github.com/basecamp/bc3-api/blob/master/sections/todos.md#complete-a-to-do
|
75
88
|
def complete_todo(todo)
|
76
|
-
|
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)
|
77
131
|
end
|
78
132
|
end
|
79
133
|
end
|
data/lib/camper/client.rb
CHANGED
data/lib/camper/error.rb
CHANGED
data/lib/camper/request.rb
CHANGED
@@ -93,7 +93,7 @@ module Camper
|
|
93
93
|
|
94
94
|
full_endpoint = override_path ? @path : @client.api_endpoint + @path
|
95
95
|
|
96
|
-
full_endpoint =
|
96
|
+
full_endpoint = UrlUtils.transform(full_endpoint)
|
97
97
|
|
98
98
|
return full_endpoint, params
|
99
99
|
end
|
@@ -138,17 +138,6 @@ module Camper
|
|
138
138
|
{ 'Authorization' => "Bearer #{@client.access_token}" }
|
139
139
|
end
|
140
140
|
|
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
141
|
def body_to_json?(params)
|
153
142
|
@method == 'post' && params.key?(:body)
|
154
143
|
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.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- renehernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -112,6 +112,8 @@ files:
|
|
112
112
|
- examples/messages.rb
|
113
113
|
- examples/oauth.rb
|
114
114
|
- examples/obtain_acces_token.rb
|
115
|
+
- examples/people.rb
|
116
|
+
- examples/todolists.rb
|
115
117
|
- examples/todos.rb
|
116
118
|
- lib/camper.rb
|
117
119
|
- lib/camper/api/comments.rb
|
@@ -119,6 +121,7 @@ files:
|
|
119
121
|
- lib/camper/api/people.rb
|
120
122
|
- lib/camper/api/projects.rb
|
121
123
|
- lib/camper/api/resource.rb
|
124
|
+
- lib/camper/api/todolists.rb
|
122
125
|
- lib/camper/api/todos.rb
|
123
126
|
- lib/camper/authorization.rb
|
124
127
|
- lib/camper/client.rb
|
@@ -130,6 +133,7 @@ files:
|
|
130
133
|
- lib/camper/request.rb
|
131
134
|
- lib/camper/resource.rb
|
132
135
|
- lib/camper/resources/project.rb
|
136
|
+
- lib/camper/url_utils.rb
|
133
137
|
- lib/camper/version.rb
|
134
138
|
homepage: https://github.com/renehernandez/camper
|
135
139
|
licenses:
|