lib/trav3.rb in trav3-0.2.5 vs lib/trav3.rb in trav3-0.3.0
- old
+ new
@@ -1,30 +1,29 @@
# frozen_string_literal: true
# rubocop:disable Metrics/ClassLength
require 'trav3/version'
+require 'forwardable'
+require 'trav3/errors'
+require 'trav3/response'
require 'trav3/pagination'
require 'trav3/options'
require 'trav3/headers'
-require 'trav3/result'
require 'trav3/rest'
# Trav3 project namespace
module Trav3
- API_ROOT = 'https://api.travis-ci.org'
-
# An abstraction for the Travis CI v3 API
#
# @author Daniel P. Clark https://6ftdan.com
# @!attribute [r] api_endpoint
# @return [String] API endpoint
# @!attribute [r] options
# @return [Options] Request options object
# @!attribute [r] headers
# @return [Headers] Request headers object
class Travis
- API_ENDPOINT = API_ROOT
attr_reader :api_endpoint
attr_reader :options
attr_reader :headers
# @param repo [String] github_username/repository_name
@@ -32,11 +31,11 @@
# conform to valid repository identifier format
# @return [Travis]
def initialize(repo)
validate_repo_format repo
- @api_endpoint = API_ENDPOINT
+ @api_endpoint = 'https://api.travis-ci.org'
@repo = sanitize_repo_name repo
initial_defaults
end
@@ -58,11 +57,11 @@
# Set as many options as you'd like for collections queried via an API request
# @param key [Symbol, String] name for value to set
# @param value [Symbol, String, Integer] value for key
# @return [self]
def defaults(**args)
- (@options ||= Options.new).build(**args)
+ (@options ||= Options.new).build(args)
self
end
# Set as many headers as you'd like for API requests
#
@@ -71,11 +70,11 @@
# @overload h(key: value, ...)
# @param key [Symbol, String] name for value to set
# @param value [Symbol, String, Integer] value for key
# @return [self]
def h(**args)
- (@headers ||= Headers.new).build(**args)
+ (@headers ||= Headers.new).build(args)
self
end
# 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.
#
@@ -768,11 +767,11 @@
# @return [Success, RequestError]
def lint(yaml_content)
validate_string yaml_content
ct = headers.remove(:'Content-Type')
- result = post("#{without_repo}/lint", body: yaml_content)
+ result = post("#{without_repo}/lint", yaml_content)
h('Content-Type': ct) if ct
result
end
# An individual log.
@@ -1048,10 +1047,135 @@
else
get("#{without_repo}/owner/#{owner}")
end
end
+ # Document `resources/preference/overview` not found.
+ #
+ # ## Attributes
+ #
+ # **Standard Representation**
+ #
+ # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
+ #
+ # Name Type Description
+ # name Unknown The preference's name.
+ # value Unknown The preference's value.
+ #
+ # **Minimal Representation**
+ #
+ # Included when the resource is returned as part of another resource.
+ #
+ # Name Type Description
+ # name Unknown The preference's name.
+ # value Unknown The preference's value.
+ #
+ # ## Actions
+ #
+ # **For Organization**
+ #
+ # Document `resources/preference/actions/for_organization` not found.
+ #
+ # GET <code>/org/{organization.id}/preference/{preference.name}</code>
+ #
+ # Template Variable Type Description
+ # organization.id Integer Value uniquely identifying the organization.
+ # preference.name Unknown The preference's name.
+ # Query Parameter Type Description
+ # include [String] List of attributes to eager load.
+ #
+ # **Update**
+ #
+ # Document `resources/preference/actions/update` not found.
+ #
+ # PATCH <code>/org/{organization.id}/preference/{preference.name}</code>
+ #
+ # Template Variable Type Description
+ # organization.id Integer Value uniquely identifying the organization.
+ # preference.name Unknown The preference's name.
+ # Accepted Parameter Type Description
+ # preference.value Unknown The preference's value.
+ #
+ # PATCH <code>/preference/{preference.name}</code>
+ #
+ # Template Variable Type Description
+ # preference.name Unknown The preference's name.
+ # Accepted Parameter Type Description
+ # preference.value Unknown The preference's value.
+ #
+ # **Find**
+ #
+ # Document `resources/preference/actions/find` not found.
+ #
+ # GET <code>/preference/{preference.name}</code>
+ #
+ # Template Variable Type Description
+ # preference.name Unknown The preference's name.
+ # Query Parameter Type Description
+ # include [String] List of attributes to eager load.
+ #
+ # @param key [String] preference name to get or set
+ # @param value [String] optional value to set preference
+ # @param org_id [String, Integer] optional keyword argument for an organization id
+ # @return [Success, RequestError]
+ def preference(key, value = nil, org_id: nil)
+ if org_id
+ validate_number org_id
+ org_id = "/org/#{org_id}"
+ end
+
+ if value.nil?
+ get("#{without_repo}#{org_id}/preference/#{key}")
+ else
+ patch("#{without_repo}#{org_id}/preference/#{key}", 'preference.value' => value)
+ end
+ end
+
+ # Document `resources/preferences/overview` not found.
+ #
+ # ## Attributes
+ #
+ # Name Type Description
+ # preferences [Preferenc] List of preferences.
+ #
+ # ## Actions
+ #
+ # **For Organization**
+ #
+ # Document `resources/preferences/actions/for_organization` not found.
+ #
+ # GET <code>/org/{organization.id}/preferences</code>
+ #
+ # Template Variable Type Description
+ # organization.id Integer Value uniquely identifying the organization.
+ # Query Parameter Type Description
+ # include [String] List of attributes to eager load.
+ #
+ # Example: GET /org/87/preferences
+ #
+ # **For User**
+ #
+ # Document `resources/preferences/actions/for_user` not found.
+ #
+ # GET <code>/preferences</code>
+ #
+ # Query Parameter Type Description
+ # include [String] List of attributes to eager load.
+ #
+ # Example: GET /preferences
+ #
+ # @param org_id [String, Integer] optional organization id
+ # @return [Success, RequestError]
+ def preferences(org_id = nil)
+ if org_id
+ validate_number org_id
+ org_id = "/org/#{org_id}"
+ end
+
+ get("#{without_repo}#{org_id}/preferences")
+ end
+
# A list of repositories for the current user.
#
# ## Attributes
#
# Name Type Description
@@ -1836,10 +1960,22 @@
def get(url, raw_reply = false)
Trav3::REST.get(self, url, raw_reply)
end
+ def get_path(url)
+ get("#{without_repo}#{url}")
+ end
+
+ def get_path_with_opts(url)
+ url, opt = url.match(/(.+)\?(.*)/)&.captures || url
+ opts.immutable do |o|
+ o.send(:update, opt)
+ get_path("#{url}#{opts}")
+ end
+ end
+
def initial_defaults
defaults(limit: 25)
h('Content-Type': 'application/json')
h('Accept': 'application/json')
h('Travis-API-Version': 3)
@@ -1855,11 +1991,11 @@
def patch(url, data)
Trav3::REST.patch(self, url, data)
end
- def post(url, fields = {})
- Trav3::REST.post(self, url, fields)
+ def post(url, body = nil)
+ Trav3::REST.post(self, url, body)
end
def validate_api_endpoint(input)
raise InvalidAPIEndpoint unless /^https:\/\/api\.travis-ci\.(?:org|com)$/.match? input
end