Module: Travis::Client::Methods
- Included in:
- Travis::CLI::ApiCommand, Namespace, Session
- Defined in:
- lib/travis/client/methods.rb
Instance Method Summary collapse
- #access_token ⇒ Object
- #access_token=(token) ⇒ Object
- #account(name) ⇒ Object
- #accounts ⇒ Object
- #api_endpoint ⇒ Object
- #api_endpoint=(uri) ⇒ Object
- #artifact(id) ⇒ Object (also: #log)
- #broadcasts ⇒ Object
- #build(id) ⇒ Object
- #cancel(entity) ⇒ Object
- #explicit_api_endpoint? ⇒ Boolean
- #github_auth(github_token) ⇒ Object
- #hooks ⇒ Object
- #job(id) ⇒ Object
- #lint(body) ⇒ Object
- #listen(*entities, &block) ⇒ Object
- #logout ⇒ Object
- #regenerate_token ⇒ Object
- #remove_token ⇒ Object
- #repo(id_or_slug) ⇒ Object
- #repos(params = {}) ⇒ Object
- #restart(entity) ⇒ Object
- #user ⇒ Object
Instance Method Details
#access_token ⇒ Object
9 10 11 |
# File 'lib/travis/client/methods.rb', line 9 def access_token session.access_token end |
#access_token=(token) ⇒ Object
13 14 15 |
# File 'lib/travis/client/methods.rb', line 13 def access_token=(token) session.access_token = token end |
#account(name) ⇒ Object
68 69 70 |
# File 'lib/travis/client/methods.rb', line 68 def account(name) session.find_one(Account, name) end |
#accounts ⇒ Object
72 73 74 |
# File 'lib/travis/client/methods.rb', line 72 def accounts session.find_many(Account, all: true) end |
#api_endpoint ⇒ Object
17 18 19 |
# File 'lib/travis/client/methods.rb', line 17 def api_endpoint session.uri end |
#api_endpoint=(uri) ⇒ Object
35 36 37 38 |
# File 'lib/travis/client/methods.rb', line 35 def api_endpoint=(uri) @explicit_api_endpoint = true session.uri = uri end |
#artifact(id) ⇒ Object Also known as: log
56 57 58 |
# File 'lib/travis/client/methods.rb', line 56 def artifact(id) session.find_one(Artifact, id) end |
#broadcasts ⇒ Object
76 77 78 |
# File 'lib/travis/client/methods.rb', line 76 def broadcasts session.find_many(Broadcast) end |
#build(id) ⇒ Object
48 49 50 |
# File 'lib/travis/client/methods.rb', line 48 def build(id) session.find_one(Build, id) end |
#cancel(entity) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/travis/client/methods.rb', line 89 def cancel(entity) raise Error, "cannot cancel a #{entity.class.one}" unless entity.cancelable? session.post_raw("/#{entity.class.many}/#{entity.id}/cancel") entity.reload end |
#explicit_api_endpoint? ⇒ Boolean
31 32 33 |
# File 'lib/travis/client/methods.rb', line 31 def explicit_api_endpoint? @explicit_api_endpoint ||= false end |
#github_auth(github_token) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/travis/client/methods.rb', line 21 def github_auth(github_token) reply = session.post_raw('/auth/github', github_token:) unless reply.respond_to?(:key?) && reply.key?('access_token') raise InvalidTokenError, 'token is invalid, or does not have sufficient scope; see https://docs.travis-ci.com/user/github-oauth-scopes/ for more information on scope' end session.access_token = reply['access_token'] end |
#hooks ⇒ Object
128 129 130 |
# File 'lib/travis/client/methods.rb', line 128 def hooks session.get('hooks')['hooks'] end |
#job(id) ⇒ Object
52 53 54 |
# File 'lib/travis/client/methods.rb', line 52 def job(id) session.find_one(Job, id) end |
#lint(body) ⇒ Object
122 123 124 125 126 |
# File 'lib/travis/client/methods.rb', line 122 def lint(body) body = body.to_yaml unless body.is_a? String result = session.post_raw('/lint', 'content' => body) LintResult.new(result) end |
#listen(*entities, &block) ⇒ Object
116 117 118 119 120 |
# File 'lib/travis/client/methods.rb', line 116 def listen(*entities, &block) listener = Listener.new(session) listener.subscribe(*entities, &block) listener.listen end |
#logout ⇒ Object
96 97 98 |
# File 'lib/travis/client/methods.rb', line 96 def logout session.get_raw('/logout') end |
#regenerate_token ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/travis/client/methods.rb', line 100 def regenerate_token session.headers['Travis-Api-Version'] = '3' token = session.patch_raw('/access_token') session.headers.delete('Travis-Api-Version') token end |
#remove_token ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/travis/client/methods.rb', line 108 def remove_token session.headers['Travis-Api-Version'] = '3' resp = session.delete_raw('/access_token') session.headers.delete('Travis-Api-Version') resp end |
#repo(id_or_slug) ⇒ Object
44 45 46 |
# File 'lib/travis/client/methods.rb', line 44 def repo(id_or_slug) session.find_one(Repository, id_or_slug) end |
#repos(params = {}) ⇒ Object
40 41 42 |
# File 'lib/travis/client/methods.rb', line 40 def repos(params = {}) session.find_many(Repository, params) end |
#restart(entity) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/travis/client/methods.rb', line 80 def restart(entity) # btw, internally we call this reset, not restart, as it resets the state machine # but we thought that would be too confusing raise Error, "cannot restart a #{entity.class.one}" unless entity.restartable? session.post_raw("/#{entity.class.many}/#{entity.id}/restart") entity.reload end |
#user ⇒ Object
62 63 64 65 66 |
# File 'lib/travis/client/methods.rb', line 62 def user session.find_one(User) rescue NotFound raise NotLoggedIn, 'currently not logged in' end |