Class: Curl::Json
- Inherits:
-
Object
- Object
- Curl::Json
- Defined in:
- lib/searchlink/curl/json.rb
Overview
Class for CURLing a JSON response
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url, data: nil, headers: nil, compressed: false, symbolize_names: false) ⇒ Curl::Json
constructor
Create a new Curl::Json page object.
- #path(path, json = @json) ⇒ Object
Constructor Details
#initialize(url, data: nil, headers: nil, compressed: false, symbolize_names: false) ⇒ Curl::Json
Create a new Curl::Json page object
17 18 19 20 21 22 23 24 |
# File 'lib/searchlink/curl/json.rb', line 17 def initialize(url, data: nil, headers: nil, compressed: false, symbolize_names: false) @curl = TTY::Which.which("curl") page = curl_json(url, data: data, headers: headers, compressed: compressed, symbolize_names: symbolize_names) @url = page[:url] @code = page[:code] @json = page[:json] @headers = page[:headers] end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/searchlink/curl/json.rb', line 6 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/searchlink/curl/json.rb', line 6 def headers @headers end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
6 7 8 |
# File 'lib/searchlink/curl/json.rb', line 6 def json @json end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/searchlink/curl/json.rb', line 6 def url @url end |
Instance Method Details
#path(path, json = @json) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/searchlink/curl/json.rb', line 26 def path(path, json = @json) parts = path.split(/./) target = json parts.each do |part| target = if part =~ /(?<key>[^\[]+)\[(?<int>\d+)\]/ target[key][int.to_i] else target[part] end end target end |