Class: Kickboxer::Request
- Inherits:
-
Object
- Object
- Kickboxer::Request
- Defined in:
- lib/kickboxer/request.rb
Constant Summary collapse
- BASE_URL =
"https://api.fullcontact.com/v2"
Class Method Summary collapse
Instance Method Summary collapse
- #build_url(options = {}) ⇒ Object
-
#initialize(action) ⇒ Request
constructor
A new instance of Request.
- #run(options = {}) ⇒ Object
Constructor Details
#initialize(action) ⇒ Request
Returns a new instance of Request.
11 12 13 |
# File 'lib/kickboxer/request.rb', line 11 def initialize(action) @action = action end |
Class Method Details
.run(action, options = {}) ⇒ Object
40 41 42 |
# File 'lib/kickboxer/request.rb', line 40 def self.run(action, ={}) new(action).run() end |
Instance Method Details
#build_url(options = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/kickboxer/request.rb', line 15 def build_url(={}) [:apiKey] = Kickboxer.api_key raise NoApiKeyError unless [:apiKey] querystring = .map{|k,v| "#{ k }=#{ URI.escape v }" } * '&' "#{ BASE_URL }/#{ @action }.json?#{ querystring }" end |
#run(options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kickboxer/request.rb', line 23 def run(={}) debug = .delete(:debug) || Kickboxer.debug response = open build_url() body = response.read if debug filename = debug.is_a?(String) ? debug : @action.gsub('/', '-') File.open("#{ filename }.json","w"){|out| out.puts body } end data = JSON.parse(body) code, text = response.status Response.new data.update(status_code: code.to_i, status_text: text) end |