camper 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +3 -2
- data/camper.gemspec +1 -0
- data/examples/people.rb +1 -0
- data/examples/projects.rb +12 -0
- data/lib/camper/api/projects.rb +97 -0
- data/lib/camper/core_extensions/object.rb +156 -0
- data/lib/camper/request.rb +1 -1
- data/lib/camper/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b8a4cdfcb11473573ac1bb1f600964f12f8722093a8a9446a47d1594e4a0963
|
4
|
+
data.tar.gz: 43810e0cf19d16b5a2a71789401758f497dfa46d43e70ea8c9e9e5a8160bcb51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 261ab2cdc09cae324aef2183d5bba9fa087c87337f2b7fe5e007bb91af4c2a6abb56f32a158437f2f71e1acc5670f76fe612911810402e60647c161733bf6199
|
7
|
+
data.tar.gz: fe517bdf6508916f6cd037424f6e95a589e1ad27303e25b385d44d51c19c722e7d47ad9d1de28bab7f2da5bbe5ffd05f8255cf4400cff980b6cb31f9594e7f59
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,12 @@
|
|
4
4
|
|
5
5
|
**Implemented enhancements:**
|
6
6
|
|
7
|
+
- Complete projects api [\#51](https://github.com/renehernandez/camper/pull/51)
|
8
|
+
|
9
|
+
## [v0.0.9](https://github.com/renehernandez/camper/tree/v0.0.9) (2020-10-28)
|
10
|
+
|
11
|
+
**Implemented enhancements:**
|
12
|
+
|
7
13
|
- Split todos and todolists APIs [\#47](https://github.com/renehernandez/camper/pull/47)
|
8
14
|
|
9
15
|
**Merged pull requests:**
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
camper (0.0.
|
4
|
+
camper (0.0.9)
|
5
|
+
concurrent-ruby (~> 1.1)
|
5
6
|
httparty (~> 0.18)
|
6
7
|
rack-oauth2 (~> 1.14)
|
7
8
|
|
@@ -87,7 +88,7 @@ GEM
|
|
87
88
|
thread_safe (~> 0.1)
|
88
89
|
unicode-display_width (1.7.0)
|
89
90
|
yard (0.9.25)
|
90
|
-
zeitwerk (2.4.
|
91
|
+
zeitwerk (2.4.1)
|
91
92
|
|
92
93
|
PLATFORMS
|
93
94
|
ruby
|
data/camper.gemspec
CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
|
29
29
|
spec.add_dependency 'httparty', '~> 0.18'
|
30
30
|
spec.add_dependency 'rack-oauth2', '~> 1.14'
|
31
|
+
spec.add_dependency 'concurrent-ruby', '~> 1.1'
|
31
32
|
|
32
33
|
spec.add_development_dependency 'rake', '~> 13.0'
|
33
34
|
spec.add_development_dependency 'rspec', '~> 3.9'
|
data/examples/people.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'camper'
|
4
|
+
|
5
|
+
client = Camper.client
|
6
|
+
|
7
|
+
project = client.project(ENV['PROJECT_ID'])
|
8
|
+
|
9
|
+
puts "Project name: #{project.name}"
|
10
|
+
puts "Project description: #{project.description}"
|
11
|
+
|
12
|
+
client.update_project(project, name: 'Hermes Testing', description: 'Hermes integration testing')
|
data/lib/camper/api/projects.rb
CHANGED
@@ -1,15 +1,112 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Camper::Client
|
4
|
+
# Defines methods related to projects.
|
5
|
+
# @see https://github.com/basecamp/bc3-api/blob/master/sections/projects.md
|
4
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
|
5
17
|
def projects(options = {})
|
6
18
|
get('/projects', options)
|
7
19
|
end
|
8
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
|
9
32
|
def project(id)
|
33
|
+
raise Camper::Error::InvalidParameter, id if id.blank?
|
34
|
+
|
10
35
|
get("/projects/#{id}")
|
11
36
|
end
|
12
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
|
+
|
13
110
|
def message_board(project)
|
14
111
|
board = project.message_board
|
15
112
|
get(board.url, override_path: true)
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Copied from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/blank.rb
|
3
|
+
|
4
|
+
require 'concurrent/map'
|
5
|
+
|
6
|
+
class Object
|
7
|
+
# An object is blank if it's false, empty, or a whitespace string.
|
8
|
+
# For example, +nil+, '', ' ', [], {}, and +false+ are all blank.
|
9
|
+
#
|
10
|
+
# This simplifies
|
11
|
+
#
|
12
|
+
# !address || address.empty?
|
13
|
+
#
|
14
|
+
# to
|
15
|
+
#
|
16
|
+
# address.blank?
|
17
|
+
#
|
18
|
+
# @return [true, false]
|
19
|
+
def blank?
|
20
|
+
respond_to?(:empty?) ? !!empty? : !self
|
21
|
+
end
|
22
|
+
|
23
|
+
# An object is present if it's not blank.
|
24
|
+
#
|
25
|
+
# @return [true, false]
|
26
|
+
def present?
|
27
|
+
!blank?
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the receiver if it's present otherwise returns +nil+.
|
31
|
+
# <tt>object.presence</tt> is equivalent to
|
32
|
+
#
|
33
|
+
# object.present? ? object : nil
|
34
|
+
#
|
35
|
+
# For example, something like
|
36
|
+
#
|
37
|
+
# state = params[:state] if params[:state].present?
|
38
|
+
# country = params[:country] if params[:country].present?
|
39
|
+
# region = state || country || 'US'
|
40
|
+
#
|
41
|
+
# becomes
|
42
|
+
#
|
43
|
+
# region = params[:state].presence || params[:country].presence || 'US'
|
44
|
+
#
|
45
|
+
# @return [Object]
|
46
|
+
def presence
|
47
|
+
self if present?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class NilClass
|
52
|
+
# +nil+ is blank:
|
53
|
+
#
|
54
|
+
# nil.blank? # => true
|
55
|
+
#
|
56
|
+
# @return [true]
|
57
|
+
def blank?
|
58
|
+
true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class FalseClass
|
63
|
+
# +false+ is blank:
|
64
|
+
#
|
65
|
+
# false.blank? # => true
|
66
|
+
#
|
67
|
+
# @return [true]
|
68
|
+
def blank?
|
69
|
+
true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class TrueClass
|
74
|
+
# +true+ is not blank:
|
75
|
+
#
|
76
|
+
# true.blank? # => false
|
77
|
+
#
|
78
|
+
# @return [false]
|
79
|
+
def blank?
|
80
|
+
false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class Array
|
85
|
+
# An array is blank if it's empty:
|
86
|
+
#
|
87
|
+
# [].blank? # => true
|
88
|
+
# [1,2,3].blank? # => false
|
89
|
+
#
|
90
|
+
# @return [true, false]
|
91
|
+
alias_method :blank?, :empty?
|
92
|
+
end
|
93
|
+
|
94
|
+
class Hash
|
95
|
+
# A hash is blank if it's empty:
|
96
|
+
#
|
97
|
+
# {}.blank? # => true
|
98
|
+
# { key: 'value' }.blank? # => false
|
99
|
+
#
|
100
|
+
# @return [true, false]
|
101
|
+
alias_method :blank?, :empty?
|
102
|
+
end
|
103
|
+
|
104
|
+
class String
|
105
|
+
BLANK_RE = /\A[[:space:]]*\z/
|
106
|
+
ENCODED_BLANKS = Concurrent::Map.new do |h, enc|
|
107
|
+
h[enc] = Regexp.new(BLANK_RE.source.encode(enc), BLANK_RE.options | Regexp::FIXEDENCODING)
|
108
|
+
end
|
109
|
+
|
110
|
+
# A string is blank if it's empty or contains whitespaces only:
|
111
|
+
#
|
112
|
+
# ''.blank? # => true
|
113
|
+
# ' '.blank? # => true
|
114
|
+
# "\t\n\r".blank? # => true
|
115
|
+
# ' blah '.blank? # => false
|
116
|
+
#
|
117
|
+
# Unicode whitespace is supported:
|
118
|
+
#
|
119
|
+
# "\u00a0".blank? # => true
|
120
|
+
#
|
121
|
+
# @return [true, false]
|
122
|
+
def blank?
|
123
|
+
# The regexp that matches blank strings is expensive. For the case of empty
|
124
|
+
# strings we can speed up this method (~3.5x) with an empty? call. The
|
125
|
+
# penalty for the rest of strings is marginal.
|
126
|
+
empty? ||
|
127
|
+
begin
|
128
|
+
BLANK_RE.match?(self)
|
129
|
+
rescue Encoding::CompatibilityError
|
130
|
+
ENCODED_BLANKS[self.encoding].match?(self)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
class Numeric #:nodoc:
|
136
|
+
# No number is blank:
|
137
|
+
#
|
138
|
+
# 1.blank? # => false
|
139
|
+
# 0.blank? # => false
|
140
|
+
#
|
141
|
+
# @return [false]
|
142
|
+
def blank?
|
143
|
+
false
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
class Time #:nodoc:
|
148
|
+
# No Time is blank:
|
149
|
+
#
|
150
|
+
# Time.now.blank? # => false
|
151
|
+
#
|
152
|
+
# @return [false]
|
153
|
+
def blank?
|
154
|
+
false
|
155
|
+
end
|
156
|
+
end
|
data/lib/camper/request.rb
CHANGED
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.10
|
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-30 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
|
@@ -113,6 +127,7 @@ files:
|
|
113
127
|
- examples/oauth.rb
|
114
128
|
- examples/obtain_acces_token.rb
|
115
129
|
- examples/people.rb
|
130
|
+
- examples/projects.rb
|
116
131
|
- examples/todolists.rb
|
117
132
|
- examples/todos.rb
|
118
133
|
- lib/camper.rb
|
@@ -126,6 +141,7 @@ files:
|
|
126
141
|
- lib/camper/authorization.rb
|
127
142
|
- lib/camper/client.rb
|
128
143
|
- lib/camper/configuration.rb
|
144
|
+
- lib/camper/core_extensions/object.rb
|
129
145
|
- lib/camper/error.rb
|
130
146
|
- lib/camper/logging.rb
|
131
147
|
- lib/camper/paginated_response.rb
|