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.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/crowdflower/base.rb', line 40 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
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/crowdflower/base.rb', line 56 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] || {})) self.class.send(method_id, url(path), ) else super end end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
38 39 40 |
# File 'lib/crowdflower/base.rb', line 38 def domain @domain end |
#domain_base ⇒ Object (readonly)
Returns the value of attribute domain_base.
38 39 40 |
# File 'lib/crowdflower/base.rb', line 38 def domain_base @domain_base end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
38 39 40 |
# File 'lib/crowdflower/base.rb', line 38 def key @key end |
#public_port ⇒ Object (readonly)
Returns the value of attribute public_port.
38 39 40 |
# File 'lib/crowdflower/base.rb', line 38 def public_port @public_port end |
#ssl_port ⇒ Object (readonly)
Returns the value of attribute ssl_port.
38 39 40 |
# File 'lib/crowdflower/base.rb', line 38 def ssl_port @ssl_port end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
38 39 40 |
# File 'lib/crowdflower/base.rb', line 38 def version @version end |
Instance Method Details
#crowdflower_base ⇒ String
Returns the base crowdflower domain from the api url’s domain.
74 75 76 77 |
# File 'lib/crowdflower/base.rb', line 74 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
85 86 87 |
# File 'lib/crowdflower/base.rb', line 85 def public_url "#{crowdflower_base}:#{public_port}" end |