Class: TenderImport::ZendeskApiImport::Client
- Inherits:
-
Object
- Object
- TenderImport::ZendeskApiImport::Client
- Includes:
- Log
- Defined in:
- lib/tender_import/zendesk_api_import.rb
Overview
}}}
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#subdomain ⇒ Object
readonly
Returns the value of attribute subdomain.
Attributes included from Log
Instance Method Summary collapse
- #entries(forum_id) ⇒ Object
- #forums ⇒ Object
-
#initialize(options = nil) ⇒ Client
constructor
If no options are provided they will be obtained from the command-line.
- #open_tickets ⇒ Object
- #posts(entry_id) ⇒ Object
- #to_s ⇒ Object
-
#user(user_id) ⇒ Object
API helpers # {{{.
- #users ⇒ Object
Methods included from 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( = nil) @opts = || @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
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
27 28 29 |
# File 'lib/tender_import/zendesk_api_import.rb', line 27 def conn @conn end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
27 28 29 |
# File 'lib/tender_import/zendesk_api_import.rb', line 27 def opts @opts end |
#subdomain ⇒ Object (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 |
#forums ⇒ Object
59 60 61 |
# File 'lib/tender_import/zendesk_api_import.rb', line 59 def forums fetch_resource("forums.json") end |
#open_tickets ⇒ Object
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_s ⇒ Object
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 |
#users ⇒ Object
55 56 57 |
# File 'lib/tender_import/zendesk_api_import.rb', line 55 def users fetch_paginated_resources("users.json?page=%d") end |