Class: TenderImport::ZendeskApiImport::Client

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/tender_import/zendesk_api_import.rb

Overview

}}}

Instance Attribute Summary collapse

Attributes included from Log

#logger

Instance Method Summary collapse

Methods included from Log

#debug, #log

Constructor Details

#initialize(options = nil) ⇒ Client

If no options are provided they will be obtained from the command-line.

The options are subdomain, email and password.

There is also an optional logger option, for use with Ruby/Rails



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tender_import/zendesk_api_import.rb', line 34

def initialize(options = nil)
  @opts = options || command_line_options
  @subdomain = opts[:subdomain]
  @logger = opts[:logger] || Logger.new(STDOUT).tap {|l| l.level = Logger::INFO}
  @conn = Faraday::Connection.new("https://#{subdomain}.zendesk.com") do |b|
    b.adapter :net_http
    #b.use ResponseJSON
    b.response :yajl
  end
  conn.basic_auth(opts[:email], opts[:password])
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



27
28
29
# File 'lib/tender_import/zendesk_api_import.rb', line 27

def conn
  @conn
end

#optsObject (readonly)

Returns the value of attribute opts.



27
28
29
# File 'lib/tender_import/zendesk_api_import.rb', line 27

def opts
  @opts
end

#subdomainObject (readonly)

Returns the value of attribute subdomain.



27
28
29
# File 'lib/tender_import/zendesk_api_import.rb', line 27

def subdomain
  @subdomain
end

Instance Method Details

#entries(forum_id) ⇒ Object



63
64
65
# File 'lib/tender_import/zendesk_api_import.rb', line 63

def entries forum_id
  fetch_paginated_resources("forums/#{forum_id}/entries.json?page=%d")
end

#forumsObject



59
60
61
# File 'lib/tender_import/zendesk_api_import.rb', line 59

def forums
  fetch_resource("forums.json")
end

#open_ticketsObject



71
72
73
# File 'lib/tender_import/zendesk_api_import.rb', line 71

def open_tickets
  fetch_paginated_resources("search.json?query=type:ticket+status:open+status:pending+status:new&page=%d")
end

#posts(entry_id) ⇒ Object



67
68
69
# File 'lib/tender_import/zendesk_api_import.rb', line 67

def posts entry_id
  fetch_paginated_resources("entries/#{entry_id}/posts.json?page=%d", 'posts')
end

#to_sObject



46
47
48
# File 'lib/tender_import/zendesk_api_import.rb', line 46

def to_s
  "#{self.class.name} (#{subdomain})"
end

#user(user_id) ⇒ Object

API helpers # {{{



51
52
53
# File 'lib/tender_import/zendesk_api_import.rb', line 51

def user user_id
  fetch_resource("users/#{user_id}.json")
end

#usersObject



55
56
57
# File 'lib/tender_import/zendesk_api_import.rb', line 55

def users
  fetch_paginated_resources("users.json?page=%d")
end