Module: Hitblocks

Defined in:
lib/hitblocks.rb,
lib/hitblocks/hit.rb,
lib/hitblocks/item.rb,
lib/hitblocks/list.rb,
lib/hitblocks/error.rb,
lib/hitblocks/errors.rb,
lib/hitblocks/version.rb,
lib/hitblocks/hitblock.rb

Defined Under Namespace

Classes: APIKeyIncorrect, APIKeyNotSet, Error, HIT, Hitblock, Item, List, MissingParametersError

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_baseObject

Returns the value of attribute api_base.



20
21
22
# File 'lib/hitblocks.rb', line 20

def api_base
  @api_base
end

.api_keyObject

Returns the value of attribute api_key.



20
21
22
# File 'lib/hitblocks.rb', line 20

def api_key
  @api_key
end

Class Method Details

.construct_error(parsed_response) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/hitblocks.rb', line 47

def self.construct_error(parsed_response)
  error = parsed_response["error"]
  if error.nil?
    error = parsed_response["errors"]
  end
  Hitblocks::Error.new(
    error: error,
    status: parsed_response["status"]
  )
end

.construct_from(response) ⇒ Object



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

def self.construct_from(response)
  parsed_response = response.parsed_response
  if parsed_response["object"]
    self.send("construct_#{parsed_response["object"]}", parsed_response)
  else
    construct_error(parsed_response)
  end
end

.construct_HIT(parsed_response) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/hitblocks.rb', line 27

def self.construct_HIT(parsed_response)
  Hitblocks::HIT.new(
    url: parsed_response["url"],
    service: parsed_response["service"],
    status: parsed_response["status"],
    created: parsed_response["created"],
    item: construct_item(parsed_response["item"])
  )
end

.construct_hitblock(parsed_response) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/hitblocks.rb', line 80

def self.construct_hitblock(parsed_response)
  Hitblocks::Hitblock.new(
    id: parsed_response["id"],
    title: parsed_response["title"],
    description: parsed_response["description"],
    type: parsed_response["type"],
    created: parsed_response["created"],
    cost_per_item: parsed_response["cost_per_item"],
    workers_per_item: parsed_response["workers_per_item"],
    currency: parsed_response["currency"],
    items: construct_items(parsed_response["items"])
  )
end

.construct_item(item) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/hitblocks.rb', line 69

def self.construct_item(item)
  Hitblocks::Item.new(
    id: item["id"],
    type: item["type"],
    created: item["created"],
    cost: item["cost"],
    currency: item["currency"],
    status: item["status"]
  )
end

.construct_items(item_list) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/hitblocks.rb', line 94

def self.construct_items(item_list)
  items = []

  item_list.each do |item|
    items.push(Hitblocks::Item.new(
      id: item["id"],
      type: item["type"],
      created: item["created"],
      cost: item["cost"],
      currency: item["currency"],
      status: item["status"]
    ))
  end

  return items
end

.construct_list(parsed_response) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/hitblocks.rb', line 58

def self.construct_list(parsed_response)
  data = parsed_response["data"]
  list_items = []
  data.each do |object|
    list_items.push(self.send("construct_#{object["object"]}", object))
  end
  Hitblocks::List.new(
    data: list_items
  )
end