camp3 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1494749b2bca6c9abf1b88fb92f095cb7b9a304a7109984dc625a1db82bd3983
4
- data.tar.gz: 62cb4e89f50f16c162e8c74e06286fe8437980d5f542751a1b3cb49a3b38475e
3
+ metadata.gz: c51061a5954cc07915e99c8e709dde954de59d976664b0fafc0f4e8029d28505
4
+ data.tar.gz: 98cfe680d84287497ac4c0d8ab6bcdcde00fb9f41ab0b444e90a368cc2a472f4
5
5
  SHA512:
6
- metadata.gz: 173586f31acad3b9d8219694c3268d5611d8c24eddf057f552c8fd3ab757745eb21a0ed4adb7d729da12e7e650c919602b5856bf595fad9ca6d8c94a90534b9c
7
- data.tar.gz: 403f48695817d15d305ec6aca49c3bf91aecb76cce9292001dbbd8505fdff54284d2c585178c364a1c45e44d0a28a1bda5dd50f6477e4efde3e85b12a7168fe7
6
+ metadata.gz: 4697b931b0e50fdd54e7345de1ebf552f4a5daad1dfb1472773890c5ac107a2a9c512d2dfdf0a852c40650212ea3d3fcff508f23be27c73686fbe2b83539b55f
7
+ data.tar.gz: 736fe2af5f5eb1599920d9466f52ab60ab637e6356886115b1ff9b9b07822c6030359070e04f9bbc39f5a9eccae96c624be5e984f180f459883cd2178290dd43
@@ -1,10 +1,3 @@
1
- # This workflow uses actions that are not certified by GitHub.
2
- # They are provided by a third-party and are governed by
3
- # separate terms of service, privacy policy, and support
4
- # documentation.
5
- # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
- # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
-
8
1
  name: CI
9
2
 
10
3
  on:
@@ -34,3 +27,27 @@ jobs:
34
27
  gem install bundler --no-document
35
28
  bundle install --jobs 4 --retry 3
36
29
  bundle exec rake
30
+
31
+ changelog_prerelease:
32
+ name: Update Changelog For Prerelease
33
+ runs-on: ubuntu-latest
34
+ if: github.ref == 'refs/heads/master'
35
+ steps:
36
+ - name: Checkout code
37
+ uses: actions/checkout@v2
38
+ with:
39
+ ref: master
40
+ - name: Update Changelog
41
+ uses: heinrichreimer/github-changelog-generator-action@v2.1.1
42
+ with:
43
+ token: ${{ secrets.GITHUB_TOKEN }}
44
+ issues: true
45
+ issuesWoLabels: true
46
+ pullRequests: true
47
+ prWoLabels: true
48
+ unreleased: true
49
+ addSections: '{"documentation":{"prefix":"**Documentation:**","labels":["documentation"]}}'
50
+ - uses: stefanzweifel/git-auto-commit-action@v4
51
+ with:
52
+ commit_message: Update Changelog for PR
53
+ file_pattern: CHANGELOG.md
@@ -10,16 +10,29 @@ jobs:
10
10
  name: Update Changelog
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
+ - name: Get version from tag
14
+ env:
15
+ GITHUB_REF: ${{ github.ref }}
16
+ run: |
17
+ export CURRENT_VERSION=${GITHUB_TAG/refs\/tags\/v/}
18
+ echo "::set-env name=CURRENT_VERSION::$CURRENT_VERSION"
13
19
  - name: Checkout code
14
20
  uses: actions/checkout@v2
21
+ with:
22
+ ref: master
15
23
  - name: Update Changelog
16
24
  uses: heinrichreimer/github-changelog-generator-action@v2.1.1
17
25
  with:
18
26
  token: ${{ secrets.GITHUB_TOKEN }}
27
+ issues: true
28
+ issuesWoLabels: true
29
+ pullRequests: true
30
+ prWoLabels: true
31
+ addSections: '{"documentation":{"prefix":"**Documentation:**","labels":["documentation"]}}'
19
32
  - uses: stefanzweifel/git-auto-commit-action@v4
20
33
  with:
21
34
  # Required
22
- commit_message: Update Changelog
35
+ commit_message: Update Changelog for tag ${{ env.CURRENT_VERSION }}
23
36
  file_pattern: CHANGELOG.md
24
37
 
25
38
  release_notes:
@@ -0,0 +1,38 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased](https://github.com/renehernandez/camp3/tree/HEAD)
4
+
5
+ **Implemented enhancements:**
6
+
7
+ - Request a new access token once it expires [\#13](https://github.com/renehernandez/camp3/issues/13)
8
+ - Retry for new access token [\#16](https://github.com/renehernandez/camp3/pull/16)
9
+
10
+ **Fixed bugs:**
11
+
12
+ - Remove unreleasedLabel field [\#15](https://github.com/renehernandez/camp3/pull/15)
13
+
14
+ **Documentation:**
15
+
16
+ - Initial documentation [\#5](https://github.com/renehernandez/camp3/issues/5)
17
+ - Update docs for retry [\#17](https://github.com/renehernandez/camp3/pull/17)
18
+ - Add section to categorize documentation changes [\#14](https://github.com/renehernandez/camp3/pull/14)
19
+ - Docs [\#10](https://github.com/renehernandez/camp3/pull/10)
20
+
21
+ ## [v0.0.2](https://github.com/renehernandez/camp3/tree/v0.0.2) (2020-07-07)
22
+
23
+ **Implemented enhancements:**
24
+
25
+ - Manage release metadata [\#4](https://github.com/renehernandez/camp3/issues/4)
26
+ - Implement release metadata management [\#9](https://github.com/renehernandez/camp3/pull/9)
27
+ - Unify Resource and ObjectifiedHash classes [\#3](https://github.com/renehernandez/camp3/pull/3)
28
+ - Added utility method to transform web URLs [\#2](https://github.com/renehernandez/camp3/pull/2)
29
+
30
+ **Fixed bugs:**
31
+
32
+ - Added missing import [\#1](https://github.com/renehernandez/camp3/pull/1)
33
+
34
+ ## [v0.0.1](https://github.com/renehernandez/camp3/tree/v0.0.1) (2020-06-29)
35
+
36
+
37
+
38
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
@@ -0,0 +1,183 @@
1
+ # Contributing to Camp3
2
+
3
+ Please take a moment to review this document in order to make the contribution
4
+ process easy and effective for everyone involved!
5
+
6
+ ## Using the issue tracker
7
+
8
+ You can use the issues tracker for:
9
+
10
+ * [bug reports](#bug-reports)
11
+ * [feature requests](#feature-requests)
12
+ * [submitting pull requests](#pull-requests)
13
+
14
+ Use [Stackoverflow](http://stackoverflow.com/) for questions and personal support requests.
15
+
16
+ ## Bug reports
17
+
18
+ A bug is a _demonstrable problem_ that is caused by the code in the repository.
19
+ Good bug reports are extremely helpful - thank you!
20
+
21
+ Guidelines for bug reports:
22
+
23
+ 1. **Use the GitHub issue search** — check if the issue has already been
24
+ reported.
25
+
26
+ 2. **Check if the issue has been fixed** — try to reproduce it using the
27
+ `master` branch in the repository.
28
+
29
+ 3. **Isolate and report the problem** — ideally create a reduced test
30
+ case.
31
+
32
+ Please try to be as detailed as possible in your report. Include information about
33
+ your Ruby and Camp3 client. Please provide steps to
34
+ reproduce the issue as well as the outcome you were expecting! All these details
35
+ will help developers to fix any potential bugs.
36
+
37
+ Example:
38
+
39
+ > Short and descriptive example bug report title
40
+ >
41
+ > A summary of the issue and the environment in which it occurs. If suitable,
42
+ > include the steps required to reproduce the bug.
43
+ >
44
+ > 1. This is the first step
45
+ > 2. This is the second step
46
+ > 3. Further steps, etc.
47
+ >
48
+ > Any other information you want to share that is relevant to the issue being
49
+ > reported. This might include the lines of code that you have identified as
50
+ > causing the bug, and potential solutions (and your opinions on their
51
+ > merits).
52
+
53
+ ## Feature requests
54
+
55
+ Feature requests are welcome. But take a moment to find out whether your idea
56
+ fits with the scope and aims of the project. It's up to *you* to make a strong
57
+ case to convince the community of the merits of this feature.
58
+ Please provide as much detail and context as possible.
59
+
60
+ ## Contributing Documentation
61
+
62
+ Code documentation has a special convention: it uses [YARD](http://yardoc.org/)
63
+ formatting and the first paragraph is considered to be a short summary.
64
+
65
+ For methods say what it will do. For example write something like:
66
+
67
+ ```ruby
68
+ # Reverses the contents of a String or IO object.
69
+ #
70
+ # @param [String, #read] contents the contents to reverse
71
+ # @return [String] the contents reversed lexically
72
+ def reverse(contents)
73
+ contents = contents.read if contents.respond_to? :read
74
+ contents.reverse
75
+ end
76
+ ```
77
+
78
+ For classes, modules say what it is. For example write something like:
79
+
80
+ ```ruby
81
+ # Defines methods related to groups.
82
+ module Groups
83
+ ```
84
+
85
+ Keep in mind that the documentation notes might show up in a summary somewhere,
86
+ long texts in the documentation notes create very ugly summaries. As a rule of thumb
87
+ anything longer than 80 characters is too long.
88
+
89
+ Try to keep unnecessary details out of the first paragraph, it's only there to
90
+ give a user a quick idea of what the documented "thing" does/is. The rest of the
91
+ documentation notes can contain the details, for example parameters and what
92
+ is returned.
93
+
94
+ If possible include examples
95
+
96
+ This makes it easy to test the examples so that they don't go stale and examples
97
+ are often a great help in explaining what a method does.
98
+
99
+ ## Pull requests
100
+
101
+ Good pull requests - patches, improvements, new features - are a fantastic
102
+ help. They should remain focused in scope and avoid containing unrelated
103
+ commits.
104
+
105
+ **IMPORTANT**: By submitting a patch, you agree that your work will be
106
+ licensed under the license used by the project.
107
+
108
+ If you have any large pull request in mind (e.g. implementing features,
109
+ refactoring code, etc), **please ask first** otherwise you risk spending
110
+ a lot of time working on something that the project's developers might
111
+ not want to merge into the project.
112
+
113
+ Please adhere to the coding conventions in the project (indentation,
114
+ accurate comments, etc.) and don't forget to add your own tests and
115
+ documentation. When working with git, we recommend the following process
116
+ in order to craft an excellent pull request:
117
+
118
+ 1. [Fork](https://help.github.com/articles/fork-a-repo/) the project, clone your fork,
119
+ and configure the remotes:
120
+
121
+ ```sh
122
+ # Clone your fork of the repo into the current directory
123
+ git clone https://github.com/<your-username>/camp3
124
+ # Navigate to the newly cloned directory
125
+ cd camp3
126
+ # Assign the original repo to a remote called "upstream"
127
+ git remote add upstream https://github.com/renehernandez/camp3
128
+ ```
129
+
130
+ 2. If you cloned a while ago, get the latest changes from upstream:
131
+
132
+ ```bash
133
+ git checkout master
134
+ git pull upstream master
135
+ ```
136
+
137
+ 3. Create a new topic branch (off of `master`) to contain your feature, change,
138
+ or fix.
139
+
140
+ **IMPORTANT**: Making changes in `master` is discouraged. You should always
141
+ keep your local `master` in sync with upstream `master` and make your
142
+ changes in topic branches.
143
+
144
+ ```sh
145
+ git checkout -b <topic-branch-name>
146
+ ```
147
+
148
+ 4. Commit your changes in logical chunks. Keep your commit messages organized,
149
+ with a short description in the first line and more detailed information on
150
+ the following lines. Feel free to use Git's
151
+ [interactive rebase](https://help.github.com/articles/about-git-rebase/)
152
+ feature to tidy up your commits before making them public.
153
+
154
+ 5. Make sure all the tests are still passing.
155
+
156
+ ```sh
157
+ rake
158
+ ```
159
+
160
+ 6. Push your topic branch up to your fork:
161
+
162
+ ```sh
163
+ git push origin <topic-branch-name>
164
+ ```
165
+
166
+ 7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
167
+ with a clear title and description.
168
+
169
+ 8. If you haven't updated your pull request for a while, you should consider
170
+ rebasing on master and resolving any conflicts.
171
+
172
+ **IMPORTANT**: _Never ever_ merge upstream `master` into your branches. You
173
+ should always `git rebase` on `master` to bring your changes up to date when
174
+ necessary.
175
+
176
+ ```sh
177
+ git checkout master
178
+ git pull upstream master
179
+ git checkout <your-topic-branch>
180
+ git rebase master
181
+ ```
182
+
183
+ Thank you for your contributions!
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- camp3 (0.0.1)
4
+ camp3 (0.0.2)
5
5
  httparty (~> 0.18)
6
6
  rack-oauth2 (~> 1.14)
7
7
 
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # camp3 ![CI](https://github.com/renehernandez/camp3/workflows/CI/badge.svg) [![Gem Version](https://badge.fury.io/rb/camp3.svg)](https://badge.fury.io/rb/camp3)
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/camp3`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Camp3 is a Ruby wrapper for the [Basecamp 3 API](https://github.com/basecamp/bc3-api).
6
4
 
7
5
  ## Installation
8
6
 
@@ -14,22 +12,82 @@ gem 'camp3'
14
12
 
15
13
  And then execute:
16
14
 
17
- $ bundle
15
+ ```bash
16
+ $ bundle
17
+ ```
18
18
 
19
19
  Or install it yourself as:
20
20
 
21
- $ gem install camp3
21
+ ```bash
22
+ $ gem install camp3
23
+ ```
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ Configuration example:
28
+
29
+ ```ruby
30
+ require 'camp3'
31
+
32
+ Camp3.configure do |config|
33
+ config.client_id = ENV['BASECAMP3_CLIENT_ID']
34
+ config.client_secret = ENV['BASECAMP3_CLIENT_SECRET']
35
+ config.account_number = ENV['BASECAMP3_ACCOUNT_NUMBER']
36
+ config.refresh_token = ENV['BASECAMP3_REFRESH_TOKEN']
37
+ config.access_token = ENV['BASECAMP3_ACCESS_TOKEN']
38
+ end
39
+ ```
40
+
41
+ For more complex examples, we recommend using a client, instead of the top level `Camp3` wrapper. A `client` has a builtin mechanism to retry requests when the access token has expired and update its information (so it will use the new access token instead of the old one), as oppose to the top level `Camp3` which would request a new access token every time a request were to be made.
42
+
43
+ Example getting list of TODOs:
44
+
45
+ ```ruby
46
+ require 'camp3'
47
+
48
+ Camp3.configure do |config|
49
+ config.client_id = ENV['BASECAMP3_CLIENT_ID']
50
+ config.client_secret = ENV['BASECAMP3_CLIENT_SECRET']
51
+ config.account_number = ENV['BASECAMP3_ACCOUNT_NUMBER']
52
+ config.refresh_token = ENV['BASECAMP3_REFRESH_TOKEN']
53
+ config.access_token = ENV['BASECAMP3_ACCESS_TOKEN']
54
+ end
55
+
56
+ client = Camp3.client
26
57
 
27
- ## Development
58
+ projects = client.projects
28
59
 
29
- 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.
60
+ projects.each do |p|
61
+ puts "Project: #{p.inspect}"
30
62
 
31
- 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
+ puts "Todo set: #{p.todoset.inspect}"
64
+
65
+ todoset = client.todoset(p)
66
+
67
+ client.todolists(todoset).each do |list|
68
+ puts "Todolist: #{list.title}"
69
+
70
+ client.todos(list).each do |todo|
71
+ puts todo.inspect
72
+ end
73
+ end
74
+ end
75
+ ```
76
+
77
+ For more examples, check the [examples](examples/) folder
32
78
 
33
79
  ## Contributing
34
80
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/camp3.
81
+ Check out the [Contributing](CONTRIBUTING.md) page.
82
+
83
+ ## Changelog
84
+
85
+ For inspecting the changes and tag releases, check the [Changelog](CHANGELOG.md) page
86
+
87
+ ## Appreciation
88
+
89
+ The gem code structure and documentation is based on the awesome [NARKOZ/gitlab gem](https://github.com/narkoz/gitlab)
90
+
91
+ ## License
92
+
93
+ Checkout the [LICENSE](LICENSE) for details
@@ -8,15 +8,17 @@ Camp3.configure do |config|
8
8
  config.access_token = ENV['BASECAMP3_ACCESS_TOKEN']
9
9
  end
10
10
 
11
- projects = Camp3.projects
11
+ client = Camp3.client
12
+
13
+ projects = client.projects
12
14
 
13
15
  projects.each do |p|
14
16
  puts "Project: #{p.name}"
15
17
 
16
- message_board = Camp3.message_board(p)
18
+ message_board = client.message_board(p)
17
19
  puts "Message Board: #{message_board.title}"
18
20
 
19
- messages = Camp3.messages(message_board)
21
+ messages = client.messages(message_board)
20
22
 
21
23
  messages.each do |msg|
22
24
  puts msg.inspect
@@ -6,13 +6,15 @@ Camp3.configure do |config|
6
6
  config.redirect_uri = ENV['BASECAMP3_REDIRECT_URI']
7
7
  end
8
8
 
9
+ client = Camp3.client
10
+
9
11
  # Get the authorization uri
10
- puts Camp3.authorization_uri
12
+ puts client.authorization_uri
11
13
 
12
14
  # Once you have received the auth code from basecamp, you can proceed with the following step
13
15
  # This will update the configuration with the corresponding tokens
14
16
  # Store the tokens in a safe place
15
- token = Camp3.authorize! ENV['BASECAMP3_ACCESS_CODE']
17
+ token = client.authorize! ENV['BASECAMP3_ACCESS_CODE']
16
18
 
17
19
  # Print refresh token
18
20
  puts token.refresh_token
@@ -8,19 +8,21 @@ Camp3.configure do |config|
8
8
  config.access_token = ENV['BASECAMP3_ACCESS_TOKEN']
9
9
  end
10
10
 
11
- projects = Camp3.projects
11
+ client = Camp3.client
12
+
13
+ projects = client.projects
12
14
 
13
15
  projects.each do |p|
14
16
  puts "Project: #{p.inspect}"
15
17
 
16
18
  puts "Todo set: #{p.todoset.inspect}"
17
19
 
18
- todoset = Camp3.todoset(p)
20
+ todoset = client.todoset(p)
19
21
 
20
- Camp3.todolists(todoset).each do |list|
22
+ client.todolists(todoset).each do |list|
21
23
  puts "Todolist: #{list.title}"
22
24
 
23
- Camp3.todos(list).each do |todo|
25
+ client.todos(list).each do |todo|
24
26
  puts todo.inspect
25
27
  end
26
28
  end
@@ -17,30 +17,6 @@ module Camp3
17
17
  extend Logging
18
18
  extend Configuration
19
19
 
20
- # def self.authorize!(auth_code)
21
- # tokens = client.authorize!(auth_code)
22
-
23
- # Resource.configure(Camp3.access_token)
24
-
25
- # tokens
26
- # end
27
-
28
- # def self.update_access_token!(refresh_token = nil)
29
- # refresh_token = Camp3.refresh_token unless refresh_token
30
-
31
- # tokens = client.update_access_token!(refresh_token)
32
-
33
- # Resource.configure(Camp3.access_token)
34
-
35
- # tokens
36
- # end
37
-
38
- # def self.configure
39
- # yield self
40
-
41
- # Resource.configure(Camp3.access_token) if Camp3.access_token
42
- # end
43
-
44
20
  # Alias for Camp3::Client.new
45
21
  #
46
22
  # @return [Camp3::Client]
@@ -59,8 +59,8 @@ module Camp3
59
59
  private
60
60
 
61
61
  def store_tokens(token)
62
- Camp3.access_token = token.access_token
63
- Camp3.refresh_token = token.refresh_token
62
+ @access_token = token.access_token
63
+ @refresh_token = token.refresh_token
64
64
  end
65
65
  end
66
66
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Camp3
4
4
  # Wrapper for the Camp3 REST API.
5
- class Client < Request
5
+ class Client
6
6
  Dir[File.expand_path('api/*.rb', __dir__)].each { |f| require f }
7
7
 
8
8
  # Keep in alphabetical order
@@ -23,8 +23,18 @@ module Camp3
23
23
  (Configuration::VALID_OPTIONS_KEYS).each do |key|
24
24
  send("#{key}=", options[key]) if options[key]
25
25
  end
26
+ end
27
+
28
+ %w[get post put delete].each do |method|
29
+ define_method method do |path, options = {}|
30
+ response, result = new_request.send(method, path, options)
31
+ return response unless result == Request::Result::AccessTokenExpired
32
+
33
+ update_access_token!
26
34
 
27
- self.class.headers 'User-Agent' => user_agent
35
+ response, _ = new_request.send(method, path, options)
36
+ response
37
+ end
28
38
  end
29
39
 
30
40
  # Text representation of the client, masking private token.
@@ -46,6 +56,10 @@ module Camp3
46
56
 
47
57
  private
48
58
 
59
+ def new_request
60
+ Request.new(@access_token, @user_agent)
61
+ end
62
+
49
63
  def only_show_last_four_chars(token)
50
64
  "#{'*' * (token.size - 4)}#{token[-4..-1]}"
51
65
  end
@@ -6,10 +6,21 @@ module Camp3
6
6
  # @private
7
7
  class Request
8
8
  include HTTParty
9
- format :plain
9
+ format :json
10
10
  headers 'Accept' => 'application/json'
11
+ parser(proc { |body, _| parse(body) })
11
12
 
12
- attr_accessor :access_token
13
+ module Result
14
+ AccessTokenExpired = 'AccessTokenExpired'
15
+
16
+ Valid = 'Valid'
17
+ end
18
+
19
+ def initialize(access_token, user_agent)
20
+ @access_token = access_token
21
+
22
+ self.class.headers 'User-Agent' => user_agent
23
+ end
13
24
 
14
25
  # Converts the response body to a Resource.
15
26
  def self.parse(body)
@@ -32,44 +43,69 @@ module Camp3
32
43
 
33
44
  # Decodes a JSON response into Ruby object.
34
45
  def self.decode(response)
35
- response ? JSON.parse(response) : {}
46
+ response ? JSON.load(response) : {}
36
47
  rescue JSON::ParserError
37
48
  raise Error::Parsing, 'The response is not a valid JSON'
38
49
  end
39
50
 
40
51
  %w[get post put delete].each do |method|
41
52
  define_method method do |path, options = {}|
42
- override_path = options.delete(:override_path)
43
53
  params = options.dup
44
-
54
+ override_path = params.delete(:override_path)
55
+
45
56
  params[:headers] ||= {}
46
- params[:headers].merge!(authorization_header)
47
57
 
48
58
  full_endpoint = override_path ? path : Camp3.api_endpoint + path
49
59
 
50
- validate self.class.send(method, full_endpoint, params)
60
+ execute_request(method, full_endpoint, params)
51
61
  end
52
62
  end
53
63
 
64
+ private
65
+
66
+ # Executes the request
67
+ def execute_request(method, endpoint, params)
68
+ params[:headers].merge!(authorization_header)
69
+
70
+ Camp3.logger.debug("Method: #{method}; URL: #{endpoint}")
71
+ response, result = validate self.class.send(method, endpoint, params)
72
+
73
+ response = extract_parsed(response) if result == Result::Valid
74
+
75
+ return response, result
76
+ end
77
+
54
78
  # Checks the response code for common errors.
55
- # Returns parsed response for successful requests.
79
+ # Informs that a retry needs to happen if request failed due to access token expiration
80
+ # @raise [Error::ResponseError] if response is an HTTP error
81
+ # @return [Response, Request::Result]
56
82
  def validate(response)
57
83
  error_klass = Error::STATUS_MAPPINGS[response.code]
84
+
85
+ if error_klass == Error::Unauthorized && response.parsed_response.error.include?("OAuth token expired (old age)")
86
+ Camp3.logger.debug("Access token expired. Please obtain a new access token")
87
+ return response, Result::AccessTokenExpired
88
+ end
89
+
58
90
  raise error_klass, response if error_klass
59
91
 
60
- parsed = self.class.parse(response)
92
+ return response, Result::Valid
93
+ end
94
+
95
+ def extract_parsed(response)
96
+ parsed = response.parsed_response
97
+
61
98
  parsed.client = self if parsed.respond_to?(:client=)
62
99
  parsed.parse_headers!(response.headers) if parsed.respond_to?(:parse_headers!)
100
+
63
101
  parsed
64
102
  end
65
103
 
66
- private
67
-
68
104
  # Returns an Authorization header hash
69
105
  #
70
106
  # @raise [Error::MissingCredentials] if access_token and auth_token are not set.
71
107
  def authorization_header
72
- raise Error::MissingCredentials, 'Please provide a access_token' unless @access_token
108
+ raise Error::MissingCredentials, 'Please provide a access_token' if @access_token.to_s.empty?
73
109
 
74
110
  { 'Authorization' => "Bearer #{@access_token}" }
75
111
  end
@@ -62,9 +62,8 @@ module Camp3
62
62
  end
63
63
 
64
64
  def self.detect_type(url)
65
- Camp3.logger.debug "Request URL: #{url}"
66
65
  case url
67
- when /#{Camp3.api_endpoint}\/projects\/\d+\.json/
66
+ when /#{Camp3.base_api_endpoint}\/\d+\/projects\/\d+\.json/
68
67
  return Project
69
68
  else
70
69
  return Resource
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Camp3
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camp3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - renehernandez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2020-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -82,6 +82,8 @@ files:
82
82
  - ".rubocop.yml"
83
83
  - ".rubocop_todo.yml"
84
84
  - ".ruby-version"
85
+ - CHANGELOG.md
86
+ - CONTRIBUTING.md
85
87
  - Gemfile
86
88
  - Gemfile.lock
87
89
  - LICENSE