Class: AskAwesomely::ApiClient

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

Constant Summary collapse

USER_AGENT =
"leemachin/ask_awesomely; (v#{AskAwesomely::VERSION})"
BASE_URL =
"https://api.typeform.io/v0.4"
ENDPOINTS =
{
  root: "/",
  create_typeform: "/forms",
  create_picture: "/images",
  create_design: "/designs"
}

Instance Method Summary collapse

Constructor Details

#initializeApiClient

Returns a new instance of ApiClient.



13
14
15
# File 'lib/ask_awesomely/api_client.rb', line 13

def initialize
  Typhoeus::Config.user_agent = USER_AGENT
end

Instance Method Details

#get_infoObject



17
18
19
20
21
22
23
24
# File 'lib/ask_awesomely/api_client.rb', line 17

def get_info
  response = request.get(
    url_for(:root),
    headers: headers
  )

  JSON.parse(response.body)
end

#submit_design(design) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/ask_awesomely/api_client.rb', line 49

def submit_design(design)
  response = request.post(
    url_for(:create_design),
    headers: headers,
    body: design.to_json
  )

  JSON.parse(response.body)
end

#submit_picture(picture) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/ask_awesomely/api_client.rb', line 39

def submit_picture(picture)
  response = request.post(
    url_for(:create_picture),
    headers: headers,
    body: picture.to_json
  )

  JSON.parse(response.body)
end

#submit_typeform(typeform) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ask_awesomely/api_client.rb', line 26

def submit_typeform(typeform)
  response = request.post(
    url_for(:create_typeform),
    headers: headers,
    body: typeform.to_json
  )

  typeform.tap do |tf|
    body = JSON.parse(response.body)
    tf.update_with_api_response(body)
  end
end