Class: Octopi::Api
- Inherits:
-
Object
- Object
- Octopi::Api
- Defined in:
- lib/octopi.rb
Direct Known Subclasses
Constant Summary collapse
- CONTENT_TYPE =
{ 'yaml' => 'application/x-yaml', 'json' => 'application/json', 'xml' => 'application/sml' }
- RETRYABLE_STATUS =
[403]
- MAX_RETRIES =
10
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#login ⇒ Object
Returns the value of attribute login.
-
#read_only ⇒ Object
Returns the value of attribute read_only.
-
#token ⇒ Object
Returns the value of attribute token.
-
#trace_level ⇒ Object
Returns the value of attribute trace_level.
Instance Method Summary collapse
- #commits(repo, opts = {}) ⇒ Object
- #find(path, result_key, resource_id) ⇒ Object
- #find_all(path, result_key, query) ⇒ Object
- #get(path, params = {}, format = "yaml") ⇒ Object
- #get_raw(path, params) ⇒ Object
-
#initialize(login = nil, token = nil, format = "yaml") ⇒ Api
constructor
A new instance of Api.
- #open_issue(user, repo, params) ⇒ Object
- #post(path, params = {}, format = "yaml") ⇒ Object
- #read_only? ⇒ Boolean
- #repository(name) ⇒ Object (also: #repo)
- #save(resource_path, data) ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(login = nil, token = nil, format = "yaml") ⇒ Api
Returns a new instance of Api.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/octopi.rb', line 70 def initialize(login = nil, token = nil, format = "yaml") @format = format @read_only = true if login @login = login @token = token @read_only = false self.class.default_params :login => login, :token => token end end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
68 69 70 |
# File 'lib/octopi.rb', line 68 def format @format end |
#login ⇒ Object
Returns the value of attribute login.
68 69 70 |
# File 'lib/octopi.rb', line 68 def login @login end |
#read_only ⇒ Object
Returns the value of attribute read_only.
68 69 70 |
# File 'lib/octopi.rb', line 68 def read_only @read_only end |
#token ⇒ Object
Returns the value of attribute token.
68 69 70 |
# File 'lib/octopi.rb', line 68 def token @token end |
#trace_level ⇒ Object
Returns the value of attribute trace_level.
68 69 70 |
# File 'lib/octopi.rb', line 68 def trace_level @trace_level end |
Instance Method Details
#commits(repo, opts = {}) ⇒ Object
109 110 111 112 |
# File 'lib/octopi.rb', line 109 def commits(repo,opts={}) branch = opts[:branch] || "master" commits = Commit.find_all(repo, branch, self) end |
#find(path, result_key, resource_id) ⇒ Object
120 121 122 |
# File 'lib/octopi.rb', line 120 def find(path, result_key, resource_id) get(path, { :id => resource_id }) end |
#find_all(path, result_key, query) ⇒ Object
124 125 126 |
# File 'lib/octopi.rb', line 124 def find_all(path, result_key, query) get(path, { :query => query, :id => query })[result_key] end |
#get(path, params = {}, format = "yaml") ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/octopi.rb', line 132 def get(path, params = {}, format = "yaml") @@retries = 0 begin trace "GET [#{format}]", "/#{format}#{path}", params submit(path, params, format) do |path, params, format| self.class.get "/#{format}#{path}" end rescue RetryableAPIError => e if @@retries < MAX_RETRIES $stderr.puts e. @@retries += 1 sleep 6 retry else raise APIError, "GitHub returned status #{e.code}, despite" + " repeating the request #{MAX_RETRIES} times. Giving up." end end end |
#get_raw(path, params) ⇒ Object
128 129 130 |
# File 'lib/octopi.rb', line 128 def get_raw(path, params) get(path, params, 'plain') end |
#open_issue(user, repo, params) ⇒ Object
98 99 100 |
# File 'lib/octopi.rb', line 98 def open_issue(user, repo, params) Issue.open(user, repo, params, self) end |
#post(path, params = {}, format = "yaml") ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/octopi.rb', line 152 def post(path, params = {}, format = "yaml") @@retries = 0 begin trace "POST", "/#{format}#{path}", params submit(path, params, format) do |path, params, format| resp = self.class.post "/#{format}#{path}", :body => params resp end rescue RetryableAPIError => e if @@retries < MAX_RETRIES $stderr.puts e. @@retries += 1 sleep 6 retry else raise APIError, "GitHub returned status #{e.code}, despite" + " repeating the request #{MAX_RETRIES} times. Giving up." end end end |
#read_only? ⇒ Boolean
82 83 84 |
# File 'lib/octopi.rb', line 82 def read_only? read_only end |
#repository(name) ⇒ Object Also known as: repo
102 103 104 105 106 |
# File 'lib/octopi.rb', line 102 def repository(name) repo = Repository.find(user, name, self) repo.api = self repo end |
#save(resource_path, data) ⇒ Object
114 115 116 117 118 |
# File 'lib/octopi.rb', line 114 def save(resource_path, data) traslate resource_path, data #still can't figure out on what format values are expected post("#{resource_path}", { :query => data }) end |