Class: CrowdFlower::Connection
- Inherits:
-
Object
- Object
- CrowdFlower::Connection
- Includes:
- HTTParty
- Defined in:
- lib/crowdflower/base.rb
Overview
an object that stores connection details; does actual http talking
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#domain_base ⇒ Object
readonly
Returns the value of attribute domain_base.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#public_port ⇒ Object
readonly
Returns the value of attribute public_port.
-
#ssl_port ⇒ Object
readonly
Returns the value of attribute ssl_port.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#crowdflower_base ⇒ String
Returns the base crowdflower domain from the api url’s domain.
-
#initialize(key, domain_base, version, ssl_port = 443, public_port = 80) ⇒ Connection
constructor
A new instance of Connection.
-
#method_missing(method_id, *args) ⇒ Object
get, post, put and delete methods.
-
#public_url ⇒ String
Returns the url to reach crowdflower regularly through a browser.
Constructor Details
#initialize(key, domain_base, version, ssl_port = 443, public_port = 80) ⇒ Connection
Returns a new instance of Connection.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/crowdflower/base.rb', line 51 def initialize(key, domain_base, version, ssl_port = 443, public_port = 80) @domain_base = domain_base @version = version @domain = "#{@domain_base}/v#{version}" @key = key @ssl_port = ssl_port @public_port = public_port begin # pass yaml file key = YAML.load_file(key) @key = key[:key] || key["key"] rescue # pass key @key = key end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args) ⇒ Object
get, post, put and delete methods
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/crowdflower/base.rb', line 67 def method_missing(method_id, *args) if [:get, :post, :put, :delete].include?(method_id) path, = *args ||= {} [:query] = (default_params.merge([:query] || {})) [:headers] = (self.class.[:headers].merge([:headers] || {})) CrowdFlower.request_hook.call(method_id, path, ) do self.class.send(method_id, url(path), ) end else super end end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
49 50 51 |
# File 'lib/crowdflower/base.rb', line 49 def domain @domain end |
#domain_base ⇒ Object (readonly)
Returns the value of attribute domain_base.
49 50 51 |
# File 'lib/crowdflower/base.rb', line 49 def domain_base @domain_base end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
49 50 51 |
# File 'lib/crowdflower/base.rb', line 49 def key @key end |
#public_port ⇒ Object (readonly)
Returns the value of attribute public_port.
49 50 51 |
# File 'lib/crowdflower/base.rb', line 49 def public_port @public_port end |
#ssl_port ⇒ Object (readonly)
Returns the value of attribute ssl_port.
49 50 51 |
# File 'lib/crowdflower/base.rb', line 49 def ssl_port @ssl_port end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
49 50 51 |
# File 'lib/crowdflower/base.rb', line 49 def version @version end |
Instance Method Details
#crowdflower_base ⇒ String
Returns the base crowdflower domain from the api url’s domain.
88 89 90 91 |
# File 'lib/crowdflower/base.rb', line 88 def crowdflower_base uri = URI.parse(domain_base) "#{uri.host.gsub("api.", "")}" end |
#public_url ⇒ String
Returns the url to reach crowdflower regularly through a browser
99 100 101 |
# File 'lib/crowdflower/base.rb', line 99 def public_url "#{crowdflower_base}:#{public_port}" end |