Class: PTLog::Pivotal::API

Inherits:
Object
  • Object
show all
Defined in:
lib/ptlog/pivotal/api.rb

Class Method Summary collapse

Class Method Details

.connectionObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/ptlog/pivotal/api.rb', line 8

def connection
  @connection ||= Faraday.new 'https://www.pivotaltracker.com/services/v5' do |faraday|
    faraday.request :json
    faraday.response :json, :content_type => /\bjson$/
    faraday.adapter Faraday.default_adapter
    faraday.headers['X-TrackerToken'] = ENV['PIVOTAL_TOKEN']
    faraday.options[:timeout] = 30
    faraday.options[:open_timeout] = 30
  end
end

.epic(id) ⇒ Object



38
39
40
# File 'lib/ptlog/pivotal/api.rb', line 38

def epic(id)
  get("epics/#{id}")
end

.get(uri) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ptlog/pivotal/api.rb', line 19

def get(uri)
  begin
    response = connection.get(uri)

    raise Pivotal::NetworkError unless response.status == 200

    response.body
  rescue Pivotal::NetworkError, Faraday::Error::TimeoutError => e
    {
      'kind' => 'error',
      'error' => 'Unable to fetch data'
    }
  end
end

.story(id) ⇒ Object



34
35
36
# File 'lib/ptlog/pivotal/api.rb', line 34

def story(id)
  get("stories/#{id}")
end