Class: Sidemash::SDK::StreamSquareRestCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/sidemash/sdk/rest_collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, pagination, items) ⇒ StreamSquareRestCollection

Returns a new instance of StreamSquareRestCollection.



9
10
11
12
13
14
# File 'lib/sidemash/sdk/rest_collection.rb', line 9

def initialize(url, pagination, items)
  @_type = 'StreamSquareRestCollection'
  @url = url
  @pagination = pagination
  @items = items
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



7
8
9
# File 'lib/sidemash/sdk/rest_collection.rb', line 7

def items
  @items
end

#paginationObject (readonly)

Returns the value of attribute pagination.



6
7
8
# File 'lib/sidemash/sdk/rest_collection.rb', line 6

def pagination
  @pagination
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/sidemash/sdk/rest_collection.rb', line 5

def url
  @url
end

Class Method Details

._typeObject



16
17
18
# File 'lib/sidemash/sdk/rest_collection.rb', line 16

def self._type
  'StreamSquareRestCollection'
end

.from_hash(h) ⇒ Object



49
50
51
52
53
# File 'lib/sidemash/sdk/rest_collection.rb', line 49

def self.from_hash(h)
  StreamSquareRestCollection.new(h['url'],
                                 Pagination.from_hash(h['pagination']),
                                 h['items'].map { |item_hash| StreamSquare.from_hash(item_hash) })
end

.from_json(js) ⇒ Object



20
21
22
23
# File 'lib/sidemash/sdk/rest_collection.rb', line 20

def self.from_json(js)
  h = JSON.parse(js)
  StreamSquareRestCollection.from_hash(h)
end

.from_remote(h) ⇒ Object



43
44
45
46
47
# File 'lib/sidemash/sdk/rest_collection.rb', line 43

def self.from_remote(h)
  StreamSquareRestCollection.new(h['url'],
                                 Pagination.from_remote(h['pagination']),
                                 h['items'].map { |item_hash| StreamSquare.from_remote(item_hash) })
end

Instance Method Details

#to_hashObject



34
35
36
37
38
39
40
41
# File 'lib/sidemash/sdk/rest_collection.rb', line 34

def to_hash
  result = {}
  result[:_type] = @_type
  result[:url] = @url
  result[:pagination] = @pagination.to_hash
  result[:items] = @items.map { |el| el.to_hash }
  result
end

#to_json(*a) ⇒ Object



55
56
57
# File 'lib/sidemash/sdk/rest_collection.rb', line 55

def to_json(*a)
  to_hash.to_json(*a)
end

#to_remoteObject



25
26
27
28
29
30
31
32
# File 'lib/sidemash/sdk/rest_collection.rb', line 25

def to_remote
  result = {}
  result[:_type] = @_type
  result[:url] = @url
  result[:pagination] = @pagination.to_remote
  result[:items] = @items.map { |el| el.to_remote }
  result
end

#to_sObject



59
60
61
62
63
# File 'lib/sidemash/sdk/rest_collection.rb', line 59

def to_s
  ('StreamSquareRestCollection(url=' + @url +
                              ', pagination=' + @pagination.to_s +
                              ', items=' + @items.to_s + ')')
end