Class: AgileZen::Client

Inherits:
Object
  • Object
show all
Includes:
Projects, Stories
Defined in:
lib/agilezen/client.rb

Overview

AgileZen::Client class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Stories

#project_stories, #project_story

Methods included from Projects

#project, #projects

Constructor Details

#initialize(options = {}) ⇒ Client

Initializer for client.



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

def initialize(options ={})
  @api_key = options[:api_key]
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/agilezen/client.rb', line 8

def api_key
  @api_key
end

Instance Method Details

#connectionObject

Builds and returns the Faraday::Connection based on set options.



26
27
28
29
30
31
32
33
# File 'lib/agilezen/client.rb', line 26

def connection
  @connection ||= Faraday::Connection.new(:url => connection_url, :headers => connection_headers) do |builder|
    builder.adapter Faraday.default_adapter
    #builder.use Faraday::Response::Yajl
    builder.use Faraday::Response::ParseJson
    builder.use Faraday::Response::Mashify
  end
end

#connection=(conn) ⇒ Object

Set the Faraday::Connection



21
22
23
# File 'lib/agilezen/client.rb', line 21

def connection=(conn)
  @connection = conn
end

#connection_headersObject

Helper method for defining globally required headers.



41
42
43
44
45
46
# File 'lib/agilezen/client.rb', line 41

def connection_headers
  headers = {
    :accept => 'application/json',
    'X-Zen-ApiKey' => @api_key
  }
end

#connection_urlObject

Helper method for determining the correct URL.



36
37
38
# File 'lib/agilezen/client.rb', line 36

def connection_url
  'https://agilezen.com'
end

#has_required_authentication?Boolean

Whether the client has the require auth to make API requests.

Returns:

  • (Boolean)


16
17
18
# File 'lib/agilezen/client.rb', line 16

def has_required_authentication?
  !@api_key.nil?
end