Class: Memair

Inherits:
Object
  • Object
show all
Defined in:
lib/memair.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Memair

Returns a new instance of Memair.



4
5
6
7
# File 'lib/memair.rb', line 4

def initialize(access_token)
  validate(access_token)
  @access_token = access_token
end

Instance Method Details

#query(query) ⇒ Object

Raises:

  • (KeyError)


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/memair.rb', line 9

def query(query)
  raise KeyError, "query is not a string." unless query.is_a? String
  attempts = 0
  begin
    sleep(attempts * 2)
    response = HTTParty.post("https://memair.com/graphql", body: query, headers: {'access-token': @access_token}, timeout: 180)
  rescue
    retry if (attempts += 1) < 8
    raise StandardError, "Can not connect to Memair"
  end
  response.to_h
end