Class: DssReuters::OnDemandExtract

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/dss_reuters.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, identifiers = nil, type = nil, fields = nil, condition = nil) ⇒ OnDemandExtract

Returns a new instance of OnDemandExtract.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/dss_reuters.rb', line 78

def initialize(session, identifiers=nil, type=nil, fields=nil, condition=nil)
  @session = session
  @status = :init
  path = "/RestApi/v1/Extractions/ExtractWithNotes"

  if fields
    options = {
      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
    }
    resp = self.class.post path, options
    if check_status(resp)
      @location = resp["location"]
    end
    @session.logger.debug resp
  end
end

Instance Attribute Details

#locationObject

Returns the value of attribute location.



65
66
67
# File 'lib/dss_reuters.rb', line 65

def location
  @location
end

#resultObject (readonly)

Returns the value of attribute result.



64
65
66
# File 'lib/dss_reuters.rb', line 64

def result
  @result
end

#statusObject

Returns the value of attribute status.



65
66
67
# File 'lib/dss_reuters.rb', line 65

def status
  @status
end

Class Method Details

.init_with_location(session, location) ⇒ Object



71
72
73
74
75
76
# File 'lib/dss_reuters.rb', line 71

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



67
68
69
# File 'lib/dss_reuters.rb', line 67

def camelize(str)
  str.to_s.split('_').collect(&:capitalize).join
end

#check_status(resp) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/dss_reuters.rb', line 112

def check_status(resp)
  if resp["status"] == "InProgress"
    @status = :in_progress
  else
    @status = :complete
  end
end

#get_resultObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/dss_reuters.rb', line 120

def get_result
  if @status == :in_progress
    options = {
      headers: {
        "Prefer" => "respond-async; wait=5",
        "Authorization" => "Token #{@session.token}"
      }
    }
    @result = self.class.get @location, options
    check_status @result
    @session.logger.debug @result
    @status
  end
end