Module: Travis::Client::Methods

Included in:
Travis::CLI::ApiCommand, Namespace, Session
Defined in:
lib/travis/client/methods.rb

Instance Method Summary collapse

Instance Method Details

#access_tokenObject



7
8
9
# File 'lib/travis/client/methods.rb', line 7

def access_token
  session.access_token
end

#access_token=(token) ⇒ Object



11
12
13
# File 'lib/travis/client/methods.rb', line 11

def access_token=(token)
  session.access_token = token
end

#account(name) ⇒ Object



61
62
63
# File 'lib/travis/client/methods.rb', line 61

def (name)
  session.find_one(Account, name)
end

#accountsObject



65
66
67
# File 'lib/travis/client/methods.rb', line 65

def accounts
  session.find_many(Account, :all => true)
end

#api_endpointObject



15
16
17
# File 'lib/travis/client/methods.rb', line 15

def api_endpoint
  session.uri
end

#api_endpoint=(uri) ⇒ Object



28
29
30
31
# File 'lib/travis/client/methods.rb', line 28

def api_endpoint=(uri)
  @explicit_api_endpoint = true
  session.uri = uri
end

#artifact(id) ⇒ Object Also known as: log



49
50
51
# File 'lib/travis/client/methods.rb', line 49

def artifact(id)
  session.find_one(Artifact, id)
end

#broadcastsObject



69
70
71
# File 'lib/travis/client/methods.rb', line 69

def broadcasts
  session.find_many(Broadcast)
end

#build(id) ⇒ Object



41
42
43
# File 'lib/travis/client/methods.rb', line 41

def build(id)
  session.find_one(Build, id)
end

#cancel(entity) ⇒ Object

Raises:



81
82
83
84
85
# File 'lib/travis/client/methods.rb', line 81

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

Returns:

  • (Boolean)


24
25
26
# File 'lib/travis/client/methods.rb', line 24

def explicit_api_endpoint?
  @explicit_api_endpoint ||= false
end

#github_auth(github_token) ⇒ Object



19
20
21
22
# File 'lib/travis/client/methods.rb', line 19

def github_auth(github_token)
  reply = session.post_raw("/auth/github", :github_token => github_token)
  session.access_token = reply["access_token"]
end

#hooksObject



99
100
101
# File 'lib/travis/client/methods.rb', line 99

def hooks
  session.get('hooks')['hooks']
end

#job(id) ⇒ Object



45
46
47
# File 'lib/travis/client/methods.rb', line 45

def job(id)
  session.find_one(Job, id)
end

#lint(body) ⇒ Object



93
94
95
96
97
# File 'lib/travis/client/methods.rb', line 93

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



87
88
89
90
91
# File 'lib/travis/client/methods.rb', line 87

def listen(*entities, &block)
  listener = Listener.new(session)
  listener.subscribe(*entities, &block)
  listener.listen
end

#repo(id_or_slug) ⇒ Object



37
38
39
# File 'lib/travis/client/methods.rb', line 37

def repo(id_or_slug)
  session.find_one(Repository, id_or_slug)
end

#repos(params = {}) ⇒ Object



33
34
35
# File 'lib/travis/client/methods.rb', line 33

def repos(params = {})
  session.find_many(Repository, params)
end

#restart(entity) ⇒ Object

Raises:



73
74
75
76
77
78
79
# File 'lib/travis/client/methods.rb', line 73

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('/requests', "#{entity.class.one}_id" => entity.id)
  entity.reload
end

#userObject



55
56
57
58
59
# File 'lib/travis/client/methods.rb', line 55

def user
  session.find_one(User)
rescue NotFound
  raise NotLoggedIn, 'currently not logged in'
end