Class: Love::Client
Overview
The Love::Client class acts as a client to the Tender REST API. Obtain an instance of this class by calling connect instead of instantiating this class directly.
You can either fetch individual resources using #get_user, #get_discussion, and similar methods, or iterate over collections using #each_discussion, #each_category and similar methods.
Constant Summary collapse
- TENDER_API_HOST =
The Tender API host to connect to.
'api.tenderapp.com'
Instance Attribute Summary collapse
-
#api_key ⇒ String
readonly
The API key to authenticate with.
-
#site ⇒ String
readonly
The site to work with.
-
#sleep_between_requests ⇒ Float
The number of seconds to sleep between paged requests.
Instance Method Summary collapse
-
#close_connection ⇒ nil
Closes the persistent connectio to the server.
-
#connected? ⇒ Boolean
true
iff the client currently has a TCP connection with the Tender API server. -
#connection ⇒ Net::HTTP
Returns a persistent connection to the server, reusing a connection of it was previously established.
-
#each_category(options = {}) {|Hash| ... } ⇒ nil
Iterates over all Tender categories.
-
#each_discussion(options = {}) {|Hash| ... } ⇒ nil
Iterates over all Tender discussions.
-
#each_queue(options = {}) {|Hash| ... } ⇒ nil
Iterates over all Tender users.
-
#each_user(options = {}) {|Hash| ... } ⇒ nil
Iterates over all Tender users.
-
#get_category(id_or_href) ⇒ Hash
Returns a single Tender category.
-
#get_discussion(id_or_href) ⇒ Hash
Returns a single Tender discussion.
-
#get_queue(id_or_href) ⇒ Hash
Returns a single Tender queue.
-
#get_user(id_or_href) ⇒ Hash
Returns a single Tender user.
-
#initialize(site, api_key, options = {}) ⇒ Client
constructor
Initializes the client.
-
#persistent? ⇒ Boolean
true
iff the client is using persistent connections.
Methods included from ResourceURI
#append_query, #collection_uri, #singleton_uri
Constructor Details
#initialize(site, api_key, options = {}) ⇒ Client
Initializes the client.
151 152 153 154 155 156 157 |
# File 'lib/love.rb', line 151 def initialize(site, api_key, = {}) @site, @api_key = site, api_key # Handle options @persistent = !![:persistent] @sleep_between_requests = [:sleep_between_requests] || 0.5 end |
Instance Attribute Details
#api_key ⇒ String (readonly)
Returns The API key to authenticate with.
139 140 141 |
# File 'lib/love.rb', line 139 def api_key @api_key end |
#site ⇒ String (readonly)
Returns The site to work with.
136 137 138 |
# File 'lib/love.rb', line 136 def site @site end |
#sleep_between_requests ⇒ Float
Returns The number of seconds to sleep between paged requests.
142 143 144 |
# File 'lib/love.rb', line 142 def sleep_between_requests @sleep_between_requests end |
Instance Method Details
#close_connection ⇒ nil
Closes the persistent connectio to the server
240 241 242 |
# File 'lib/love.rb', line 240 def close_connection @connection.finish if connected? end |
#connected? ⇒ Boolean
Returns true
iff the client currently has a TCP connection with the Tender API server.
245 246 247 |
# File 'lib/love.rb', line 245 def connected? @connection && @connection.started? end |
#connection ⇒ Net::HTTP
Returns a persistent connection to the server, reusing a connection of it was previously established.
This method is mainly used for internal use but can be used to do advanced HTTP connectivity with the Tender API server.
230 231 232 233 234 235 236 |
# File 'lib/love.rb', line 230 def connection @connection ||= Net::HTTP.new(TENDER_API_HOST, Net::HTTP.https_default_port).tap do |http| http.use_ssl = true # http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.start end end |
#each_category(options = {}) {|Hash| ... } ⇒ nil
Iterates over all Tender categories.
195 196 197 |
# File 'lib/love.rb', line 195 def each_category( = {}, &block) paged_each(collection_uri('categories'), 'categories', , &block) end |
#each_discussion(options = {}) {|Hash| ... } ⇒ nil
Iterates over all Tender discussions.
219 220 221 |
# File 'lib/love.rb', line 219 def each_discussion( = {}, &block) paged_each(collection_uri('discussions'), 'discussions', , &block) end |
#each_queue(options = {}) {|Hash| ... } ⇒ nil
Iterates over all Tender users.
203 204 205 |
# File 'lib/love.rb', line 203 def each_queue( = {}, &block) paged_each(collection_uri('queues'), 'named_queues', , &block) end |
#each_user(options = {}) {|Hash| ... } ⇒ nil
Iterates over all Tender users.
211 212 213 |
# File 'lib/love.rb', line 211 def each_user( = {}, &block) paged_each(collection_uri('users'), 'users', , &block) end |
#get_category(id_or_href) ⇒ Hash
Returns a single Tender category.
179 180 181 |
# File 'lib/love.rb', line 179 def get_category(id_or_href) get(singleton_uri(id_or_href, 'categories')) end |
#get_discussion(id_or_href) ⇒ Hash
Returns a single Tender discussion.
171 172 173 |
# File 'lib/love.rb', line 171 def get_discussion(id_or_href) get(singleton_uri(id_or_href, 'discussions')) end |
#get_queue(id_or_href) ⇒ Hash
Returns a single Tender queue.
187 188 189 |
# File 'lib/love.rb', line 187 def get_queue(id_or_href) get(singleton_uri(id_or_href, 'queues'), ) end |
#get_user(id_or_href) ⇒ Hash
Returns a single Tender user.
163 164 165 |
# File 'lib/love.rb', line 163 def get_user(id_or_href) get(singleton_uri(id_or_href, 'users')) end |
#persistent? ⇒ Boolean
Returns true
iff the client is using persistent connections.
250 251 252 |
# File 'lib/love.rb', line 250 def persistent? @persistent end |