Class: QNE::Stocks

Inherits:
Base
  • Object
show all
Includes:
QueryBuilder
Defined in:
lib/stocks.rb

Constant Summary

Constants included from QueryBuilder

QueryBuilder::OPERATORS

Instance Attribute Summary collapse

Attributes inherited from Base

#conn, #response

Instance Method Summary collapse

Methods included from QueryBuilder

#eq_query, #multi_query, #uri_query, #where

Methods inherited from Base

#initialize, #parse_to_json, #success?

Constructor Details

This class inherits a constructor from QNE::Base

Instance Attribute Details

#id ⇒ Object (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/stocks.rb', line 12

def id
  @id
end

Instance Method Details

#all(params = {}) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/stocks.rb', line 30

def all(params = {})
  @response = QNE::Stock::All.new(
    conn, params: uri_query(params)
  ).call

  parse_to_json(@response.body)
end

#find(id) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/stocks.rb', line 14

def find(id)
  finder = QNE::Stocks::Find.new(conn, id: id).call

  return unless finder.success?

  define_singleton_method 'uoms' do
    find_uoms_by_id(id)
  end

  define_singleton_method 'show' do
    @response = parse_to_json(finder.body)
  end

  self
end

#find_stocks_available_by_stock_code(stock_code) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/stocks.rb', line 46

def find_stocks_available_by_stock_code(stock_code)
  @response = QNE::Stock::Available.new(
    conn, stock_code: stock_code
  ).call

  parse_to_json(@response.body)
end

#find_uoms_by_id(id) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/stocks.rb', line 38

def find_uoms_by_id(id)
  @response = QNE::Stock::UOMs.new(
    conn, id: id
  ).call

  parse_to_json(@response.body)
end