Class: BitbucketClient
- Inherits:
-
Object
- Object
- BitbucketClient
- Defined in:
- app/clients/bitbucket_client.rb
Instance Method Summary collapse
- #conn ⇒ Object
-
#initialize(token) ⇒ BitbucketClient
constructor
A new instance of BitbucketClient.
- #refresh ⇒ Object
- #req(method, url, params = {}) ⇒ Object
- #teams ⇒ Object
Constructor Details
#initialize(token) ⇒ BitbucketClient
Returns a new instance of BitbucketClient.
3 4 5 |
# File 'app/clients/bitbucket_client.rb', line 3 def initialize(token) @token = token end |
Instance Method Details
#conn ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/clients/bitbucket_client.rb', line 22 def conn @github ||= Faraday.new(url: 'https://api.bitbucket.org/') do |faraday| faraday.request :url_encoded # form-encode POST params faraday.adapter Faraday.default_adapter # make requests with Net::HTTP faraday.response :logger # log requests to STDOUT faraday.headers['Authorization'] = "Bearer #{@token}" end end |
#refresh ⇒ Object
18 19 20 |
# File 'app/clients/bitbucket_client.rb', line 18 def refresh end |
#req(method, url, params = {}) ⇒ Object
13 14 15 16 |
# File 'app/clients/bitbucket_client.rb', line 13 def req(method, url, params={}) res = conn.send(method, url, params) JSON.parse(res.body) end |
#teams ⇒ Object
7 8 9 10 11 |
# File 'app/clients/bitbucket_client.rb', line 7 def teams req(:get, '2.0/user/orgs').map do |org| {id: org['id'], name: org['name']} end end |