Class: GlobeSSL::Products

Inherits:
Base
  • Object
show all
Defined in:
lib/globessl/products.rb

Instance Method Summary collapse

Methods inherited from Base

#inspect

Instance Method Details

#fetchObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/globessl/products.rb', line 6

def fetch
  @errors.clear
  @list.clear
  
  response = Client.get('/products/list')
  
  case response.code
  when '200'  
    json = response.body
    hash = JSON.parse(json)
    
    collection = hash["products"].inject([]) { |memo, element| memo << element.last }
  
    collection.each do |product|
      @list << Product.new(
        :id           => product["id"],
        :name         => product["name"],
        :validation   => product["validation"],
        :wildcard     => product["wildcard"],
        :multi_domain => product["mdc"],
        :min_domains  => product["mdc_min"],
        :max_domains  => product["mdc_max"],
        :brand        => product["brand"]
      )
    end
    return true
  when '400', '401', '403'
    set_errors(response)
    return false
  else
    return false
  end
end

#set_errors(response) ⇒ Object



40
41
42
43
44
# File 'lib/globessl/products.rb', line 40

def set_errors(response)
  json = response.body
  hash = JSON.parse(json)
  @errors << hash["message"]
end