Class: DssReuters::OnDemandExtract
- Inherits:
-
Object
- Object
- DssReuters::OnDemandExtract
- Includes:
- HTTParty
- Defined in:
- lib/dss_reuters.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
Returns the value of attribute location.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #camelize(str) ⇒ Object
- #check_status(resp) ⇒ Object
- #get_result ⇒ Object
-
#initialize(session, identifiers = nil, type = nil, fields = nil, condition = nil) ⇒ OnDemandExtract
constructor
A new instance of OnDemandExtract.
Constructor Details
#initialize(session, identifiers = nil, type = nil, fields = nil, condition = nil) ⇒ OnDemandExtract
Returns a new instance of OnDemandExtract.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/dss_reuters.rb', line 94 def initialize(session, identifiers=nil, type=nil, fields=nil, condition=nil) @session = session @status = :init path = "/RestApi/v1/Extractions/ExtractWithNotes" if fields = { headers: { "Prefer" => "respond-async; wait=5", "Content-Type" => "application/json; odata=minimalmetadata", "Authorization" => "Token #{@session.token}" }, body: { "ExtractionRequest" => { "@odata.type" => "#{camelize(type)}ExtractionRequest", "ContentFieldNames" => fields, "IdentifierList" => { "@odata.type" => "InstrumentIdentifierList", "InstrumentIdentifiers" => identifiers, "ValidationOptions" => nil, "UseUserPreferencesForValidationOptions" => false }, "Condition" => condition } }.to_json } if session.configured? resp = self.class.post path, if check_status(resp) @location = resp["location"] end @session.logger.debug resp else session.not_configured_error end end end |
Instance Attribute Details
#location ⇒ Object
Returns the value of attribute location.
81 82 83 |
# File 'lib/dss_reuters.rb', line 81 def location @location end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
80 81 82 |
# File 'lib/dss_reuters.rb', line 80 def result @result end |
#status ⇒ Object
Returns the value of attribute status.
81 82 83 |
# File 'lib/dss_reuters.rb', line 81 def status @status end |
Class Method Details
.init_with_location(session, location) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/dss_reuters.rb', line 87 def self.init_with_location(session, location) ins = self.new(session) ins.status = :in_progress ins.location = location ins end |
Instance Method Details
#camelize(str) ⇒ Object
83 84 85 |
# File 'lib/dss_reuters.rb', line 83 def camelize(str) str.to_s.split('_').collect(&:capitalize).join end |
#check_status(resp) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/dss_reuters.rb', line 132 def check_status(resp) if resp["status"] == "InProgress" @status = :in_progress else @status = :complete end end |
#get_result ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/dss_reuters.rb', line 140 def get_result if @status == :in_progress = { headers: { "Prefer" => "respond-async; wait=5", "Authorization" => "Token #{@session.token}" } } if @session.configured? @result = self.class.get @location, check_status @result @session.logger.debug @result @status else @session.not_configured_error end end end |