close 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +66 -0
- data/LICENSE.txt +21 -0
- data/README.md +129 -0
- data/Rakefile +12 -0
- data/lib/close/api_operations.rb +92 -0
- data/lib/close/api_resource.rb +132 -0
- data/lib/close/close_object.rb +8 -0
- data/lib/close/errors.rb +6 -0
- data/lib/close/resource/contact.rb +9 -0
- data/lib/close/resource/custom_activity_type.rb +10 -0
- data/lib/close/resource/lead.rb +9 -0
- data/lib/close/resource/task.rb +9 -0
- data/lib/close/resources.rb +4 -0
- data/lib/close/version.rb +5 -0
- data/lib/close.rb +32 -0
- data/sig/close.rbs +4 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9aa1bc5d8124785414823311b95736c9ddde2ca4c5f2746e6308443f313ace7a
|
4
|
+
data.tar.gz: e3eac1f1c53b1da521845eb66bd3a8ec6cd342c608cf216b2cef62e7b0cea410
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0a5b9a3e0ee10bced5cccad33bc838c8b156fad65c821f332f548a94d0a6eff47847a340b946b5e91b12c0503bc36c0af883347cca12aa95887ad4d62e3d3144
|
7
|
+
data.tar.gz: 991f361451aedaf253e9d602f3f8975deb3495202fb2f294c058b32b4ba83ecd20a9d262e7ab2d23aff1ba0d64dea314cfe9c0c05c8773beac094dfdcc218e64
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at steve@trurooms.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
close (0.1.0)
|
5
|
+
faraday
|
6
|
+
ostruct
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.2)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
faraday (2.6.0)
|
14
|
+
faraday-net_http (>= 2.0, < 3.1)
|
15
|
+
ruby2_keywords (>= 0.0.4)
|
16
|
+
faraday-net_http (3.0.1)
|
17
|
+
json (2.6.2)
|
18
|
+
ostruct (0.5.5)
|
19
|
+
parallel (1.22.1)
|
20
|
+
parser (3.1.2.1)
|
21
|
+
ast (~> 2.4.1)
|
22
|
+
rainbow (3.1.1)
|
23
|
+
rake (13.0.6)
|
24
|
+
regexp_parser (2.6.0)
|
25
|
+
rexml (3.2.5)
|
26
|
+
rspec (3.11.0)
|
27
|
+
rspec-core (~> 3.11.0)
|
28
|
+
rspec-expectations (~> 3.11.0)
|
29
|
+
rspec-mocks (~> 3.11.0)
|
30
|
+
rspec-core (3.11.0)
|
31
|
+
rspec-support (~> 3.11.0)
|
32
|
+
rspec-expectations (3.11.1)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.11.0)
|
35
|
+
rspec-mocks (3.11.1)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.11.0)
|
38
|
+
rspec-support (3.11.1)
|
39
|
+
rubocop (1.36.0)
|
40
|
+
json (~> 2.3)
|
41
|
+
parallel (~> 1.10)
|
42
|
+
parser (>= 3.1.2.1)
|
43
|
+
rainbow (>= 2.2.2, < 4.0)
|
44
|
+
regexp_parser (>= 1.8, < 3.0)
|
45
|
+
rexml (>= 3.2.5, < 4.0)
|
46
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
47
|
+
ruby-progressbar (~> 1.7)
|
48
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
49
|
+
rubocop-ast (1.21.0)
|
50
|
+
parser (>= 3.1.1.0)
|
51
|
+
ruby-progressbar (1.11.0)
|
52
|
+
ruby2_keywords (0.0.5)
|
53
|
+
unicode-display_width (2.3.0)
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
arm64-darwin-21
|
57
|
+
|
58
|
+
DEPENDENCIES
|
59
|
+
close!
|
60
|
+
faraday
|
61
|
+
rake (~> 13.0)
|
62
|
+
rspec (~> 3.0)
|
63
|
+
rubocop (~> 1.21)
|
64
|
+
|
65
|
+
BUNDLED WITH
|
66
|
+
2.3.7
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Steve
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# Close
|
2
|
+
|
3
|
+
This a ruby gem that provides a robust way to interact with the Close
|
4
|
+
CRM API.
|
5
|
+
|
6
|
+
It will have many features.
|
7
|
+
|
8
|
+
- [ ] Request Caching
|
9
|
+
- [ ] Request Throttling / Queueing for rate limits
|
10
|
+
- [ ] Full Documentation
|
11
|
+
- [ ] Full Test Coverage
|
12
|
+
- [ ] Full API Coverage
|
13
|
+
- [ ] Full Child Object Instances
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'close'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle install
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install close
|
30
|
+
|
31
|
+
## Configuration
|
32
|
+
|
33
|
+
The gem can be configures in the following ways:
|
34
|
+
|
35
|
+
Block Configuration
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# Block configuration
|
39
|
+
Close.configure do |config|
|
40
|
+
config.api_key = 'YOUR_API_KEY'
|
41
|
+
end
|
42
|
+
# One off settings
|
43
|
+
Close.configuration.api_key = 'YOUR_API_KEY'
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
This gem works by creating resource objects that represent resources on
|
50
|
+
the Close API. These objects can be used to make requests to the API.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
|
54
|
+
# Example Using Leads:
|
55
|
+
|
56
|
+
# Get a list of leads
|
57
|
+
leads = Close::Lead.list
|
58
|
+
|
59
|
+
# Get a single lead
|
60
|
+
lead = Close::Lead.retrieve('lead_id')
|
61
|
+
|
62
|
+
# Update the name
|
63
|
+
lead.name = 'New Name'
|
64
|
+
|
65
|
+
# Save the changes
|
66
|
+
lead.save
|
67
|
+
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
## Supported Resources
|
72
|
+
|
73
|
+
### Leads
|
74
|
+
[Close API Docs](https://developer.close.com/resources/leads/)
|
75
|
+
|
76
|
+
### Custom Activity Types
|
77
|
+
[Close API Docs](https://developer.close.com/resources/custom-activities/custom-activity-types/)
|
78
|
+
|
79
|
+
#### .list
|
80
|
+
```ruby
|
81
|
+
Close::CustomActivityType.list # => Array of [CustomActivityType]
|
82
|
+
```
|
83
|
+
|
84
|
+
#### .retrieve
|
85
|
+
```ruby
|
86
|
+
Close::CustomActivityType.retrieve('custom_activity_type_id') # => CustomActivityType
|
87
|
+
```
|
88
|
+
|
89
|
+
#### .create
|
90
|
+
```ruby
|
91
|
+
Close::CustomActivityType.create({name: 'Custom Activity Type Name'}) # => CustomActivityType
|
92
|
+
```
|
93
|
+
|
94
|
+
#### #update
|
95
|
+
```ruby
|
96
|
+
custom_activity_type = Close::CustomActivityType.retrieve('custom_activity_type_id')
|
97
|
+
custom_activity_type.name = 'New Name'
|
98
|
+
custom_activity_type.update # => Boolean
|
99
|
+
```
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
## Documentation
|
104
|
+
|
105
|
+
Aside from this README, you can find the documentation for this gem at [rubydoc.info](https://www.rubydoc.info/gems/close).
|
106
|
+
|
107
|
+
You can also generate the documentation locally by running:
|
108
|
+
|
109
|
+
$ bundle exec rake yard
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
## Development
|
114
|
+
|
115
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
116
|
+
|
117
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
118
|
+
|
119
|
+
## Contributing
|
120
|
+
|
121
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/JoyNerd/close. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/JoyNerd/close/blob/master/CODE_OF_CONDUCT.md).
|
122
|
+
|
123
|
+
## License
|
124
|
+
|
125
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
126
|
+
|
127
|
+
## Code of Conduct
|
128
|
+
|
129
|
+
Everyone interacting in the Close project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/close/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
module Close
|
2
|
+
module APIOperations
|
3
|
+
|
4
|
+
def request(method, path, params = {}, opts = {})
|
5
|
+
preflight_request(method, path, params, opts)
|
6
|
+
|
7
|
+
case method
|
8
|
+
when :get
|
9
|
+
response = get(path, params, opts)
|
10
|
+
when :post
|
11
|
+
response = post(path, params, opts)
|
12
|
+
when :put
|
13
|
+
response = put(path, params, opts)
|
14
|
+
when :delete
|
15
|
+
response = delete(path, params, opts)
|
16
|
+
end
|
17
|
+
|
18
|
+
handle_response(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
# Preflight the request to make sure things like caching are handled.
|
24
|
+
# TODO: Implement caching.
|
25
|
+
# TODO: Implement rate limiting.
|
26
|
+
def preflight_request(method, path, params = {}, opts = {})
|
27
|
+
end
|
28
|
+
|
29
|
+
# Parse the response from the API and perform error handling.
|
30
|
+
# Careful gotcha: The Close API returns a 'data' key for all responses of sets
|
31
|
+
# where individual records are just the body.
|
32
|
+
def handle_response(response)
|
33
|
+
verify_status(response)
|
34
|
+
return response.body
|
35
|
+
end
|
36
|
+
|
37
|
+
# Check the response status and raise an error if it's not 200.
|
38
|
+
# This is where we handle things like rate limiting as well.
|
39
|
+
# @param response [Faraday::Response] The response object.
|
40
|
+
# @return [Void]
|
41
|
+
# @raise [Close::Error] If the response status is not 200.
|
42
|
+
def verify_status(response)
|
43
|
+
if response.status == 401
|
44
|
+
raise Close::AuthenticationError, response.body
|
45
|
+
elsif response.status == 400
|
46
|
+
raise Close::InvalidRequestError, response.body
|
47
|
+
elsif response.status == 429
|
48
|
+
raise Close::RateLimitExceeded, response.body
|
49
|
+
elsif response.status == 500
|
50
|
+
raise Close::APIError, response.body
|
51
|
+
elsif response.status != 200 && response.status != 201 && response.status != 204
|
52
|
+
raise Close::APIError, response.body
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def get(path, params = {}, opts = {})
|
57
|
+
connection.get(path, params, opts)
|
58
|
+
end
|
59
|
+
|
60
|
+
def post(path, params = {}, opts = {})
|
61
|
+
connection.post(path, params, opts)
|
62
|
+
end
|
63
|
+
|
64
|
+
def put(path, params = {}, opts = {})
|
65
|
+
connection.put(path, params, opts)
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete(path, params = {}, opts = {})
|
69
|
+
connection.delete(path, params, opts)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Instance a new Faraday connection.
|
73
|
+
# @return [Faraday::Connection] The connection object.
|
74
|
+
def connection
|
75
|
+
raise Close::AuthenticationError, 'No API key provided.' if Close.configuration.api_key.nil?
|
76
|
+
Faraday.new(
|
77
|
+
url: 'https://api.close.com',
|
78
|
+
headers: {
|
79
|
+
accept: 'application/json',
|
80
|
+
'User-Agent' => "close-ruby/v#{Close::VERSION}",
|
81
|
+
}
|
82
|
+
) do |conn|
|
83
|
+
conn.request :authorization, :basic, Close.configuration.api_key, ''
|
84
|
+
conn.request :json
|
85
|
+
conn.response :json
|
86
|
+
conn.response :logger, Close.configuration.logger if Close.configuration.logger
|
87
|
+
conn.adapter Faraday.default_adapter
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module Close
|
2
|
+
class APIResource < CloseObject
|
3
|
+
extend APIOperations
|
4
|
+
|
5
|
+
# Easy to grok resource name.
|
6
|
+
def self.class_name
|
7
|
+
name.split('::')[-1]
|
8
|
+
end
|
9
|
+
|
10
|
+
# Available subclasses of API resource that can be instanced.
|
11
|
+
# Listed from their files in ./resource
|
12
|
+
# @return [Array] the available subclasses.
|
13
|
+
def self.available_subclasses
|
14
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'resource', '*.rb')).map do |file|
|
15
|
+
File.basename(file, '.rb').split('_').map(&:capitalize).join
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Define a resource's URL. We could probably do some magic here
|
20
|
+
# to infer the URL from the class name, but it can always be overridden.
|
21
|
+
# @return [String] the resource's URL.
|
22
|
+
# @raise [NotImplementedError] if the method is not overridden.
|
23
|
+
def self.resource_url
|
24
|
+
if self == APIResource
|
25
|
+
raise NotImplementedError.new('APIResource is an abstract class. You should perform actions on its subclasses (Lead, Opportunity, etc.)')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Retrieves a list of resources.
|
30
|
+
# @param opts [Hash] options to pass to the request.
|
31
|
+
# @return [Array] an array of resources.
|
32
|
+
def self.list(opts = {})
|
33
|
+
items = request(:get, resource_url, opts)
|
34
|
+
items['data'].map { |item| new({}, item) }
|
35
|
+
end
|
36
|
+
|
37
|
+
# Retrieve a singular resource.
|
38
|
+
# @param id [String] the resource's ID.
|
39
|
+
# @return [Close::APIResource] the resource.
|
40
|
+
def self.retrieve(id)
|
41
|
+
new({}, request(:get, "#{resource_url}#{id}/"))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Creates a resource with the given values.
|
45
|
+
# @param values [Hash] the values to create the resource with.
|
46
|
+
# @return [Close::APIResource] the created resource.
|
47
|
+
def self.create(values = {})
|
48
|
+
record = new(values, {})
|
49
|
+
record.save
|
50
|
+
record
|
51
|
+
end
|
52
|
+
|
53
|
+
# Initialize a new resource with the given values.
|
54
|
+
# @param values [Hash] the values to initialize the resource with.
|
55
|
+
# @param existing_values [Hash] the values that already exist on the server.
|
56
|
+
# @return [Close::APIResource] the initialized resource.
|
57
|
+
def initialize(values = {}, existing_values = {})
|
58
|
+
@values = {}
|
59
|
+
@new_values = values
|
60
|
+
define_accessors(existing_values)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Easily access the mixed existing and new values.
|
64
|
+
# @return [Hash] the values.
|
65
|
+
def values
|
66
|
+
@values.merge(@new_values)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Updates the resource on the server. Will not make a request
|
70
|
+
# if there are no unsaved changes.
|
71
|
+
# @return [Boolean] true if the update succeeded, false otherwise.
|
72
|
+
def update
|
73
|
+
return true unless dirty?
|
74
|
+
resp = self.class.request(:put, "#{self.class.resource_url}#{self.id}/", values)
|
75
|
+
@new_values = {}
|
76
|
+
@values = resp
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
80
|
+
# Persists the values to the server. If the resource already exists,
|
81
|
+
# it will update the resource. If the resource does not exist, it will
|
82
|
+
# create the resource.
|
83
|
+
# @return [Boolean] true if the save succeeded, false otherwise.
|
84
|
+
def save
|
85
|
+
if defined?(id) && !id.empty?
|
86
|
+
update()
|
87
|
+
else
|
88
|
+
@values = self.class.request(:post, self.class.resource_url, values)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Destroy the resource on the server.
|
93
|
+
# @return [Boolean] true if the destroy succeeded, false otherwise.
|
94
|
+
def destroy
|
95
|
+
return false if self.id.empty?
|
96
|
+
self.class.request(:delete, "#{self.class.resource_url}#{self.id}/")
|
97
|
+
true
|
98
|
+
end
|
99
|
+
|
100
|
+
# If there are unsaved/unpersisted changes to the object.
|
101
|
+
# @return [Boolean] true if there are unsaved changes, false otherwise.
|
102
|
+
def dirty?
|
103
|
+
!@new_values.empty?
|
104
|
+
end
|
105
|
+
|
106
|
+
# Override the default inspect method to show the object's values.
|
107
|
+
# @return [String] the object's values.
|
108
|
+
def inspect
|
109
|
+
str = "#<#{self.class.name}:#{self.object_id} "
|
110
|
+
fields = @values.keys.map{|field| "#{field}: #{self.send(field)}"}
|
111
|
+
str << fields.join(", ") << ">"
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
# A bunch of magic to define accessors for the resources
|
117
|
+
# values. This is to make them behave as existing objects.
|
118
|
+
# @param existing_values [Hash] the values to define accessors for.
|
119
|
+
def define_accessors(existing_values)
|
120
|
+
existing_values.each do |key, value|
|
121
|
+
@values[key] = value
|
122
|
+
define_singleton_method("#{key}") do
|
123
|
+
@new_values[key] || @values[key]
|
124
|
+
end
|
125
|
+
define_singleton_method("#{key}=") do |value|
|
126
|
+
@new_values[key] = value
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
data/lib/close/errors.rb
ADDED
data/lib/close.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "ostruct"
|
3
|
+
require "faraday"
|
4
|
+
|
5
|
+
require_relative "close/close_object"
|
6
|
+
require_relative "close/api_operations"
|
7
|
+
require_relative "close/api_resource"
|
8
|
+
require_relative "close/resources"
|
9
|
+
require_relative "close/errors"
|
10
|
+
require_relative "close/version"
|
11
|
+
|
12
|
+
module Close
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
# The default configuration object.
|
16
|
+
# @option api_key [String] The API key to use for requests.
|
17
|
+
# @option rate_limit_behavior [Symbol] :raise_error, :retry, TODO: :proactive.
|
18
|
+
# @option logger [Logger] Where, if any, to log requests.
|
19
|
+
def self.configuration
|
20
|
+
@@configuration ||= OpenStruct.new({
|
21
|
+
api_key: ENV['CLOSE_API_KEY'],
|
22
|
+
rate_limit: :raise_error,
|
23
|
+
logger: Logger.new(STDOUT),
|
24
|
+
})
|
25
|
+
end
|
26
|
+
|
27
|
+
# Allow block setting of configuration options.
|
28
|
+
def self.configure
|
29
|
+
yield(configuration)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/sig/close.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: close
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- JoyNerd LLC
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ostruct
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A ruby wrapper for the close.com API that offers caching.
|
42
|
+
email:
|
43
|
+
- developers@joynerd.io
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".rspec"
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- CHANGELOG.md
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/close.rb
|
58
|
+
- lib/close/api_operations.rb
|
59
|
+
- lib/close/api_resource.rb
|
60
|
+
- lib/close/close_object.rb
|
61
|
+
- lib/close/errors.rb
|
62
|
+
- lib/close/resource/contact.rb
|
63
|
+
- lib/close/resource/custom_activity_type.rb
|
64
|
+
- lib/close/resource/lead.rb
|
65
|
+
- lib/close/resource/task.rb
|
66
|
+
- lib/close/resources.rb
|
67
|
+
- lib/close/version.rb
|
68
|
+
- sig/close.rbs
|
69
|
+
homepage: https://github.com/joynerd/close
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata:
|
73
|
+
allowed_push_host: https://rubygems.org
|
74
|
+
homepage_uri: https://github.com/joynerd/close
|
75
|
+
source_code_uri: https://github.com/joynerd/close.git
|
76
|
+
changelog_uri: https://github.com/joynerd/changelog.md
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.6.0
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubygems_version: 3.2.3
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: A ruby wrapper for the close.com API
|
96
|
+
test_files: []
|