trav3 0.3.4 → 0.4.0

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: ed23a93da595b3da695cb6caab54e75c06f8b0dad48f9765293a21698fe1893b
4
- data.tar.gz: c6ca0a3472f8130457a2aadccdf757bfc4e8ba12c4ce43cc5bedf2e781c7a050
3
+ metadata.gz: b79ebdae779f99cce1a1ce93943918f211eeaba5d8ad67eeab8afd67af5212ce
4
+ data.tar.gz: '09df80099c63c1472d782d3829e4b53c8ef4be1241e7e0bbefbd62b3d9d6b727'
5
5
  SHA512:
6
- metadata.gz: 57991342eb7e718ba0e4441a901e7765fd2bb19159eda1e124c2e214c86e60a7ee3a040ab931a8e5829c674035522126bfcaeb7f671570876baa9a5bc9414ea2
7
- data.tar.gz: 235cbd08b2ec78926a8a142653ca98441c8063904e5686a37bf08d308c5c9495e9778023d9e8c5aac862b0ba9714f4d412e199474c7f29297297ef00899bf8b6
6
+ metadata.gz: 7f552afb48039f584aa92c38cd5b1e078ca4e5ffe66c07c93b6dbcabc891be092b89e17c2afd6e02290359990f6d612d145e50ceab13829086c738a785443e77
7
+ data.tar.gz: 3b6ed188c1a2240cc712f3c79617b078f881aafe32fdfe8956f62c505eb9b93ac90dbedaa68f470347d70cefb3526772741a2a90ec3b102657732d2b85ef8f0a
@@ -6,7 +6,3 @@ checks:
6
6
  method-count:
7
7
  config:
8
8
  threshold: 100
9
-
10
- plugins:
11
- rubocop:
12
- enabled: true
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/trav3.svg)](http://badge.fury.io/rb/trav3)
2
2
  [![Build Status](https://travis-ci.org/danielpclark/trav3.svg?branch=master)](https://travis-ci.org/danielpclark/trav3)
3
- [![Commits Since Release](https://img.shields.io/github/commits-since/danielpclark/trav3/v0.3.4.svg)](https://github.com/danielpclark/trav3/graphs/commit-activity)
3
+ [![Commits Since Release](https://img.shields.io/github/commits-since/danielpclark/trav3/v0.4.0.svg)](https://github.com/danielpclark/trav3/graphs/commit-activity)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/1ed07a4baea3832b6207/maintainability)](https://codeclimate.com/github/danielpclark/trav3/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/1ed07a4baea3832b6207/test_coverage)](https://codeclimate.com/github/danielpclark/trav3/test_coverage)
6
6
  [![Red The Docs](https://img.shields.io/badge/Read-the%20docs-blue.svg)](http://danielpclark.github.io/trav3/Trav3/Travis.html)
@@ -31,32 +31,93 @@ Or install it yourself as:
31
31
 
32
32
  ## Usage
33
33
 
34
- require 'trav3'
35
- project = Trav3::Travis.new("name/example")
36
- project.owner
37
- project.owner("owner")
38
- project.repositories
39
- project.repositories("owner")
40
- project.repository
41
- project.repository("owner/repo")
42
- project.builds
43
- project.build(12345)
44
- project.build_jobs(12345)
45
- project.job(1234)
46
- project.log(1234)
47
-
48
- # API Request Options
49
- project.defaults(limit: 25)
50
-
51
- # Pagination
52
- builds = project.builds
53
- builds.page.next
54
- builds.page.first
55
- builds.page.last
56
-
57
- # Recommended inspection
58
- builds.keys
59
- builds.dig("some_key")
34
+ You can get started with the following.
35
+
36
+ ```ruby
37
+ require 'trav3'
38
+ project = Trav3::Travis.new("name/example")
39
+ ```
40
+
41
+ When you instantiate an instance of [Trav3::Travis](http://danielpclark.github.io/trav3/Trav3/Travis.html)
42
+ you get some default headers and default options.
43
+
44
+ #### Default Options
45
+
46
+ * `limit: 25` — for limiting data queries to 25 items at most
47
+
48
+ Options can be changed via the `#options` getter method which will give you a
49
+ [Trav3::Options](http://danielpclark.github.io/trav3/Trav3/Options.html) instance.
50
+ All changes to it affect the options that the `Trav3::Travis` instance will submit
51
+ in url requests.
52
+
53
+ #### Default Headers
54
+
55
+ * `'Content-Type': 'application/json'`
56
+ * `'Accept': 'application/json'`
57
+ * `'Travis-API-Version': 3`
58
+
59
+ Headers can be changed via the `#headers` getter method which will give you a
60
+ [Trav3::Headers](http://danielpclark.github.io/trav3/Trav3/Headers.html) instance.
61
+ All changes to it affect the headers that the `Trav3::Travis` instance will submit
62
+ in url requests.
63
+
64
+ ## API
65
+
66
+ The client has the full API implemented. Here are the methods.
67
+
68
+ | | | |
69
+ |-----|-----|-----|
70
+ | [`#active`](http://danielpclark.github.io/trav3/Trav3/Travis.html#active-instance_method) | [`#beta_feature`](http://danielpclark.github.io/trav3/Trav3/Travis.html#beta_feature-instance_method) | [`#beta_features`](http://danielpclark.github.io/trav3/Trav3/Travis.html#beta_features-instance_method) |
71
+ | [`#branch`](http://danielpclark.github.io/trav3/Trav3/Travis.html#branch-instance_method) | [`#branches`](http://danielpclark.github.io/trav3/Trav3/Travis.html#branches-instance_method) | [`#broadcasts`](http://danielpclark.github.io/trav3/Trav3/Travis.html#broadcasts-instance_method) |
72
+ | [`#build`](http://danielpclark.github.io/trav3/Trav3/Travis.html#build-instance_method) | [`#builds`](http://danielpclark.github.io/trav3/Trav3/Travis.html#builds-instance_method) | [`#build_jobs`](http://danielpclark.github.io/trav3/Trav3/Travis.html#build_jobs-instance_method) |
73
+ | [`#caches`](http://danielpclark.github.io/trav3/Trav3/Travis.html#caches-instance_method) | [`#cron`](http://danielpclark.github.io/trav3/Trav3/Travis.html#cron-instance_method) | [`#crons`](http://danielpclark.github.io/trav3/Trav3/Travis.html#crons-instance_method) |
74
+ | [`#email_resubscribe`](http://danielpclark.github.io/trav3/Trav3/Travis.html#email_resubscribe-instance_method) | [`#email_unsubscribe`](http://danielpclark.github.io/trav3/Trav3/Travis.html#email_unsubscribe-instance_method) | [`#env_var`](http://danielpclark.github.io/trav3/Trav3/Travis.html#env_var-instance_method) |
75
+ | [`#env_vars`](http://danielpclark.github.io/trav3/Trav3/Travis.html#env_vars-instance_method) | [`#installation`](http://danielpclark.github.io/trav3/Trav3/Travis.html#installation-instance_method) | [`#job`](http://danielpclark.github.io/trav3/Trav3/Travis.html#job-instance_method) |
76
+ | [`#key_pair`](http://danielpclark.github.io/trav3/Trav3/Travis.html#key_pair-instance_method) | [`#key_pair_generated`](http://danielpclark.github.io/trav3/Trav3/Travis.html#key_pair_generated-instance_method) | [`#lint`](http://danielpclark.github.io/trav3/Trav3/Travis.html#lint-instance_method) |
77
+ | [`#log`](http://danielpclark.github.io/trav3/Trav3/Travis.html#log-instance_method) | [`#messages`](http://danielpclark.github.io/trav3/Trav3/Travis.html#messages-instance_method) | [`#organization`](http://danielpclark.github.io/trav3/Trav3/Travis.html#organization-instance_method) |
78
+ | [`#organizations`](http://danielpclark.github.io/trav3/Trav3/Travis.html#organizations-instance_method) | [`#owner`](http://danielpclark.github.io/trav3/Trav3/Travis.html#owner-instance_method) | [`#preference`](http://danielpclark.github.io/trav3/Trav3/Travis.html#preference-instance_method) |
79
+ | [`#preferences`](http://danielpclark.github.io/trav3/Trav3/Travis.html#preferences-instance_method) | [`#repositories`](http://danielpclark.github.io/trav3/Trav3/Travis.html#repositories-instance_method) | [`#repository`](http://danielpclark.github.io/trav3/Trav3/Travis.html#repository-instance_method) |
80
+ | [`#request`](http://danielpclark.github.io/trav3/Trav3/Travis.html#request-instance_method) | [`#requests`](http://danielpclark.github.io/trav3/Trav3/Travis.html#requests-instance_method) | [`#stages`](http://danielpclark.github.io/trav3/Trav3/Travis.html#stages-instance_method) |
81
+ | [`#setting`](http://danielpclark.github.io/trav3/Trav3/Travis.html#setting-instance_method) | [`#settings`](http://danielpclark.github.io/trav3/Trav3/Travis.html#settings-instance_method) | [`#user`](http://danielpclark.github.io/trav3/Trav3/Travis.html#user-instance_method) |
82
+
83
+
84
+ **General Usage**
85
+
86
+ ```ruby
87
+ project.owner
88
+ project.owner("owner")
89
+ project.repositories
90
+ project.repositories("owner")
91
+ project.repository
92
+ project.repository("owner/repo")
93
+ project.builds
94
+ project.build(12345)
95
+ project.build_jobs(12345)
96
+ project.job(1234)
97
+ project.log(1234)
98
+
99
+ # API Request Options
100
+ project.options.build({limit: 25})
101
+
102
+ # Pagination
103
+ builds = project.builds
104
+ builds.page.next
105
+ builds.page.first
106
+ builds.page.last
107
+
108
+ # Recommended inspection
109
+ builds.keys
110
+ builds.dig("some_key")
111
+ ```
112
+
113
+ #### Follow
114
+
115
+ Each request returns a `Trav3::Response` type of either `Trav3::Success` or `Trav3::RequestError`.
116
+ When you have an instance of `Trav3::Success` each response collection of either `Hash` or `Array` will
117
+ be an instance of `Trav3::ResponseCollection`. If the `#hash?` method responds as `true` the `#follow`
118
+ method will follow any immediate `@href` link provided in the collection. If `#hash?` produces `false`
119
+ then the collection is an Array of items and you may use the index of the item you want to follow the
120
+ `@href` with; like so `#follow(3)`.
60
121
 
61
122
  ## Development
62
123
 
@@ -37,28 +37,23 @@ module Trav3
37
37
 
38
38
  initial_defaults
39
39
  end
40
- # rubocop:disable Lint/Void
41
40
 
42
41
  # Set as the API endpoint
43
42
  #
44
43
  # @param endpoint [String] name for value to set
45
- # @return [self]
44
+ # @return [Travis]
46
45
  def api_endpoint=(endpoint)
47
46
  validate_api_endpoint endpoint
48
-
49
47
  @api_endpoint = endpoint
50
-
51
- self
52
48
  end
53
49
 
54
50
  # Set the authorization token in the requests' headers
55
51
  #
56
52
  # @param token [String] sets authorization token header
57
- # @return [self]
53
+ # @return [Travis]
58
54
  def authorization=(token)
59
55
  validate_string token
60
56
  h('Authorization': "token #{token}")
61
- self
62
57
  end
63
58
 
64
59
  # Set as many options as you'd like for collections queried via an API request
@@ -66,7 +61,7 @@ module Trav3
66
61
  # @overload defaults(key: value, ...)
67
62
  # @param key [Symbol] name for value to set
68
63
  # @param value [Symbol, String, Integer] value for key
69
- # @return [self]
64
+ # @return [Travis]
70
65
  def defaults(**args)
71
66
  (@options ||= Options.new).build(args)
72
67
  self
@@ -79,7 +74,7 @@ module Trav3
79
74
  # @overload h(key: value, ...)
80
75
  # @param key [Symbol] name for value to set
81
76
  # @param value [Symbol, String, Integer] value for key
82
- # @return [self]
77
+ # @return [Travis]
83
78
  def h(**args)
84
79
  (@headers ||= Headers.new).build(args)
85
80
  self
@@ -88,13 +83,11 @@ module Trav3
88
83
  # Change the repository this instance of `Trav3::Travis` uses.
89
84
  #
90
85
  # @param repo_name [String] github_username/repository_name
91
- # @return [self]
86
+ # @return [Travis]
92
87
  def repository=(repo_name)
93
88
  validate_repo_format repo_name
94
89
  @repo = sanitize_repo_name repo_name
95
- self
96
90
  end
97
- # rubocop:enable Lint/Void
98
91
 
99
92
  # Please Note that the naming of this endpoint may be changed. Our naming convention for this information is in flux. If you have suggestions for how this information should be presented please leave us feedback by commenting in this issue here or emailing support support@travis-ci.com.
100
93
  #
@@ -154,6 +147,102 @@ module Trav3
154
147
  get("#{without_repo}/owner/#{owner}/active")
155
148
  end
156
149
 
150
+ # A beta feature (a Travis-CI feature currently in beta).
151
+ #
152
+ # ## Attributes
153
+ #
154
+ # Name Type Description
155
+ # id Integer Value uniquely identifying the beta feature.
156
+ # name String The name of the feature.
157
+ # description String Longer description of the feature.
158
+ # enabled Boolean Indicates if the user has this feature turned on.
159
+ # feedback_url String Url for users to leave Travis CI feedback on this feature.
160
+ #
161
+ # ## Actions
162
+ #
163
+ # **Update**
164
+ #
165
+ # This will update a user's beta_feature.
166
+ #
167
+ # Use namespaced params in the request body to pass the `enabled` value (either true or false):
168
+ #
169
+ # ```bash
170
+ # curl -X PATCH \
171
+ # -H "Content-Type: application/json" \
172
+ # -H "Travis-API-Version: 3" \
173
+ # -H "Authorization: token xxxxxxxxxxxx" \
174
+ # -d '{"beta_feature.enabled":true}' \
175
+ # https://api.travis-ci.com/user/1234/{beta_feature.id}
176
+ # ```
177
+ #
178
+ # PATCH <code>/user/{user.id}/beta_feature/{beta_feature.id}</code>
179
+ #
180
+ # Template Variable Type Description
181
+ # user.id Integer Value uniquely identifying the user.
182
+ # beta_feature.id Integer Value uniquely identifying the beta feature.
183
+ # Accepted Parameter Type Description
184
+ # beta_feature.id Integer Value uniquely identifying the beta feature.
185
+ # beta_feature.enabled Boolean Indicates if the user has this feature turned on.
186
+ #
187
+ # **Delete**
188
+ #
189
+ # This will delete a user's beta feature.
190
+ #
191
+ # DELETE <code>/user/{user.id}/beta_feature/{beta_feature.id}</code>
192
+ #
193
+ # Template Variable Type Description
194
+ # user.id Integer Value uniquely identifying the user.
195
+ # beta_feature.id Integer Value uniquely identifying the beta feature.
196
+ #
197
+ # @param action [Symbol] either `:enable`, `:disable` or `:delete`
198
+ # @param beta_feature_id [String, Integer] id for the beta feature
199
+ # @param user_id [String] user id
200
+ # @return [Success, RequestError]
201
+ def beta_feature(action, beta_feature_id, user_id)
202
+ validate_number beta_feature_id
203
+ validate_number user_id
204
+
205
+ if action != :delete
206
+ params = { 'beta_feature.id' => beta_feature_id, 'beta_feature.enabled' => action == :enable }
207
+
208
+ patch("#{without_repo}/user/#{user_id}/beta_feature/#{beta_feature_id}", params)
209
+ else
210
+ delete("#{without_repo}/user/#{user_id}/beta_feature/#{beta_feature_id}")
211
+ end
212
+ end
213
+
214
+ # A list of beta features. Beta features are new Travis CI features in beta mode. They can be toggled on or off via the API or on this page on our site: https://travis-ci.com/features
215
+ #
216
+ # ## Attributes
217
+ #
218
+ # Name Type Description
219
+ # beta_features [Beta feature] List of beta_features.
220
+ #
221
+ # ## Actions
222
+ #
223
+ # **Find**
224
+ #
225
+ # This will return a list of beta features available to a user.
226
+ #
227
+ # GET <code>/user/{user.id}/beta_features</code>
228
+ #
229
+ # Template Variable Type Description
230
+ # user.id Integer Value uniquely identifying the user.
231
+ # Query Parameter Type Description
232
+ # include [String] List of attributes to eager load.
233
+ #
234
+ # Example: GET /user/119240/beta_features
235
+ #
236
+ # @note requests require an authorization token set in the headers. See: {authorization=}
237
+ #
238
+ # @param user_id [String, Integer] user id
239
+ # @return [Success, RequestError]
240
+ def beta_features(user_id)
241
+ validate_number user_id
242
+
243
+ get("#{without_repo}/user/#{user_id}/beta_features")
244
+ end
245
+
157
246
  # The branch of a GitHub repository. Useful for obtaining information about the last build on a given branch.
158
247
  #
159
248
  # **If querying using the repository slug, it must be formatted using {http://www.w3schools.com/tags/ref_urlencode.asp standard URL encoding}, including any special characters.**
@@ -281,6 +370,47 @@ module Trav3
281
370
  get("#{with_repo}/branches#{opts}")
282
371
  end
283
372
 
373
+ # A list of broadcasts for the current user.
374
+ #
375
+ # ## Attributes
376
+ #
377
+ # Name Type Description
378
+ # broadcasts [Broadcast] List of broadcasts.
379
+ #
380
+ # **Collection Items**
381
+ #
382
+ # Each entry in the broadcasts array has the following attributes:
383
+ #
384
+ # Name Type Description
385
+ # id Integer Value uniquely identifying the broadcast.
386
+ # message String Message to display to the user.
387
+ # created_at String When the broadcast was created.
388
+ # category String Broadcast category (used for icon and color).
389
+ # active Boolean Whether or not the brodacast should still be displayed.
390
+ # recipient Object Either a user, organization or repository, or null for global.
391
+ #
392
+ # ## Actions
393
+ #
394
+ # **For Current User**
395
+ #
396
+ # This will return a list of broadcasts for the current user.
397
+ #
398
+ # GET <code>/broadcasts</code>
399
+ #
400
+ # Query Parameter Type Description
401
+ # active [Boolean] Alias for broadcast.active.
402
+ # broadcast.active [Boolean] Filters broadcasts by whether or not the brodacast should still be displayed.
403
+ # include [String] List of attributes to eager load.
404
+ #
405
+ # Example: GET /broadcasts
406
+ #
407
+ # @note requests require an authorization token set in the headers. See: {authorization=}
408
+ #
409
+ # @return [Success, RequestError]
410
+ def broadcasts
411
+ get("#{without_repo}/broadcasts")
412
+ end
413
+
284
414
  # An individual build.
285
415
  #
286
416
  # ## Attributes
@@ -1086,12 +1216,7 @@ module Trav3
1086
1216
  # @param create [Hash] Optional argument. A hash of the `name`, `value`, and `public` visibleness for a env var to create
1087
1217
  # @return [Success, RequestError]
1088
1218
  def env_vars(create = nil)
1089
- if create
1090
- validate_env_var create
1091
-
1092
- return create("#{with_repo}/env_vars", env_var_keys(create))
1093
- end
1094
-
1219
+ create and return create("#{with_repo}/env_vars", env_var_keys(create))
1095
1220
  get("#{with_repo}/env_vars")
1096
1221
  end
1097
1222
 
@@ -2730,7 +2855,7 @@ module Trav3
2730
2855
  end
2731
2856
 
2732
2857
  def get_path_with_opts(url)
2733
- url, opt = url.match(/(.+)\?(.*)/)&.captures || url
2858
+ url, opt = url.match(/^(.+)\?(.*)$/)&.captures || url
2734
2859
  opts.immutable do |o|
2735
2860
  o.send(:update, opt)
2736
2861
  get_path("#{url}#{opts}")
@@ -2745,7 +2870,8 @@ module Trav3
2745
2870
  end
2746
2871
 
2747
2872
  def inject_property_name(name, hash)
2748
- return hash.map { |k, v| ["#{name}.#{k}", v] }.to_h unless hash.keys.first.match?(/\A#{name}\.\w+\z/)
2873
+ raise TypeError, "Hash expected, #{input.class} given" unless hash.is_a? Hash
2874
+ return hash.map { |k, v| ["#{name}.#{k}", v] }.to_h unless hash.keys.first.match?(/^#{name}\.\w+$/)
2749
2875
 
2750
2876
  hash
2751
2877
  end
@@ -2774,20 +2900,6 @@ module Trav3
2774
2900
  raise InvalidAPIEndpoint unless /^https:\/\/api\.travis-ci\.(?:org|com)$/.match? input
2775
2901
  end
2776
2902
 
2777
- # rubocop:disable Metrics/CyclomaticComplexity
2778
- def validate_env_var(input)
2779
- raise TypeError, "Hash expected, #{input.class} given" unless input.is_a? Hash
2780
- raise EnvVarError unless input.all? do |k, v|
2781
- k.match?(/name|value|public/) &&
2782
- case k.to_s
2783
- when /name/ then v.is_a? String
2784
- when /value/ then v.is_a? String
2785
- when /public/ then [true, false].include? v
2786
- end
2787
- end
2788
- end
2789
- # rubocop:enable Metrics/CyclomaticComplexity
2790
-
2791
2903
  def validate_number(input)
2792
2904
  raise TypeError, "Integer expected, #{input.class} given" unless number? input
2793
2905
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'error/env_var_error'
4
3
  require_relative 'error/invalid_api_endpoint'
5
4
  require_relative 'error/invalid_repository'
6
5
  require_relative 'error/unimplemented'
@@ -5,12 +5,15 @@ require 'forwardable'
5
5
  module Trav3
6
6
  class Headers
7
7
  extend Forwardable
8
- def_delegators :@heads, :each_pair
8
+ def_delegators :@heads, :each_pair, :fetch
9
9
 
10
10
  def initialize(args = {})
11
11
  build(args)
12
12
  end
13
13
 
14
+ # Add or update the request headers
15
+ #
16
+ # @return [Headers] self
14
17
  def build(args = {})
15
18
  @heads ||= {}
16
19
 
@@ -21,10 +24,18 @@ module Trav3
21
24
  self
22
25
  end
23
26
 
27
+ # Remove key/value from headers via key
28
+ #
29
+ # @param key [Symbol, String] key to look up
30
+ # @return [String, Symbol, nil] returns value if key found, `nil` otherwise.
24
31
  def remove(key)
25
32
  @heads.delete(key)
26
33
  end
27
34
 
35
+ # Add the values of one `Headers` into another
36
+ #
37
+ # @param other [Headers] instance of `Headers`
38
+ # @return [Headers]
28
39
  def +(other)
29
40
  raise TypeError, "Headers type expected, #{other.class} given" unless other.is_a? Headers
30
41
 
@@ -33,6 +44,7 @@ module Trav3
33
44
  self
34
45
  end
35
46
 
47
+ # @return [Hash] hash of the `Headers`
36
48
  def to_h
37
49
  @heads
38
50
  end
@@ -6,6 +6,9 @@ module Trav3
6
6
  build(args)
7
7
  end
8
8
 
9
+ # url safe rendering of options for the url
10
+ #
11
+ # @return [String] url options
9
12
  def opts
10
13
  if @opts.empty?
11
14
  ''
@@ -14,6 +17,9 @@ module Trav3
14
17
  end
15
18
  end
16
19
 
20
+ # Add or update url options
21
+ #
22
+ # @return [Options] self
17
23
  def build(args = {})
18
24
  @opts ||= []
19
25
 
@@ -25,6 +31,10 @@ module Trav3
25
31
  self
26
32
  end
27
33
 
34
+ # Fetch the `key=value`
35
+ #
36
+ # @param [Symbol, String] key of the key/value pair to fetch
37
+ # @return [String]
28
38
  def fetch(key)
29
39
  @opts.each do |item|
30
40
  return item if key.to_s == split.call(item).first
@@ -35,12 +45,18 @@ module Trav3
35
45
  yield
36
46
  end
37
47
 
48
+ # Fetch and remove `key=value`. Modifies `Options`.
49
+ #
50
+ # @param [Symbol, String] key of the key/value pair to fetch
51
+ # @return [String]
38
52
  def fetch!(key, &block)
39
53
  result = fetch(key, &block)
40
54
  remove(key)
41
55
  result
42
56
  end
43
57
 
58
+ # Execute a block of code and restore original `Options` state afterwards
59
+ # @yield [Options]
44
60
  def immutable
45
61
  old = @opts
46
62
  result = yield self
@@ -48,6 +64,10 @@ module Trav3
48
64
  result
49
65
  end
50
66
 
67
+ # Remove key/value from options via key
68
+ #
69
+ # @param key [Symbol, String] key to look up
70
+ # @return [String, nil] returns a `String` if key found, `nil` otherwise.
51
71
  def remove(key)
52
72
  return_value = nil
53
73
 
@@ -60,12 +80,19 @@ module Trav3
60
80
  return_value
61
81
  end
62
82
 
83
+ # this purges all options
84
+ #
85
+ # @return [Options] self
63
86
  def reset!
64
87
  @opts = []
65
88
 
66
89
  self
67
90
  end
68
91
 
92
+ # Add the values of one `Options` into another
93
+ #
94
+ # @param other [Options] instance of `Options`
95
+ # @return [Options]
69
96
  def +(other)
70
97
  raise TypeError, "Options type expected, #{other.class} given" unless other.is_a? Options
71
98
 
@@ -74,10 +101,12 @@ module Trav3
74
101
  self
75
102
  end
76
103
 
104
+ # (see #opts)
77
105
  def to_s
78
106
  opts
79
107
  end
80
108
 
109
+ # @return [Hash] hash of the `Options`
81
110
  def to_h
82
111
  @opts.map(&split).to_h
83
112
  end
@@ -48,6 +48,13 @@ module Trav3
48
48
  self[0]
49
49
  end
50
50
 
51
+ # Follows `@href` link within item.
52
+ # If `#hash?` returns `true` then `#follow` takes no parameters.
53
+ # If `#hash?` returns `false` then `#follow` takes an index parameter
54
+ # for which item in the Array you wish to follow.
55
+ #
56
+ # @param idx [Integer] (optional parameter) index of array of item to follow `@href` url from
57
+ # @return [Success, RequestError]
51
58
  def follow(idx = nil)
52
59
  if href? && !idx
53
60
  url = collection.fetch('@href')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trav3
4
- VERSION = '0.3.4'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trav3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-28 00:00:00.000000000 Z
11
+ date: 2019-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,7 +86,6 @@ files:
86
86
  - bin/console
87
87
  - bin/setup
88
88
  - lib/trav3.rb
89
- - lib/trav3/error/env_var_error.rb
90
89
  - lib/trav3/error/invalid_api_endpoint.rb
91
90
  - lib/trav3/error/invalid_repository.rb
92
91
  - lib/trav3/error/unimplemented.rb
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Trav3
4
- class EnvVarError < StandardError
5
- def message
6
- "You must provide the keys `name`, `value`, and `public`\
7
- where name and value are given String values and public is a Boolean."
8
- end
9
- end
10
- end