Class: ElectricProfile::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.

Raises:

  • (ArgumentError)


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

def initialize
  raise ArgumentError, 'Customer token is required' unless @customer_token = ENV['ELECTRIC_PROFILE_CUSTOMER_TOKEN']
  raise ArgumentError, 'API URL is required' unless @api_url = ENV['ELECTRIC_PROFILE_API_URL']

  @http_headers = {
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Accept-Charset' => 'utf-8',
    'User-Agent' => 'electric_profile_ruby',
    'Panel-Services-Auth-Token' => @customer_token
  }
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/electric_profile_ruby/client.rb', line 7

def data
  @data
end

#errorObject (readonly)

Returns the value of attribute error.



7
8
9
# File 'lib/electric_profile_ruby/client.rb', line 7

def error
  @error
end

#successfulObject (readonly)

Returns the value of attribute successful.



7
8
9
# File 'lib/electric_profile_ruby/client.rb', line 7

def successful
  @successful
end

Instance Method Details

#create_profiler(profiler_attributes) ⇒ Object



60
61
62
63
64
65
# File 'lib/electric_profile_ruby/client.rb', line 60

def create_profiler(profiler_attributes)
  uri = URI(@api_url + 'profiler')
  http_request = Net::HTTP::Post.new uri, @http_headers
  http_request.body = { "data" => profiler_attributes }.to_json
  perform_request(uri, http_request)
end

#create_question(question_attributes) ⇒ Object



34
35
36
37
38
39
# File 'lib/electric_profile_ruby/client.rb', line 34

def create_question(question_attributes)
  uri = URI(@api_url + 'question')
  http_request = Net::HTTP::Post.new uri, @http_headers
  http_request.body = { "data" => question_attributes }.to_json
  perform_request(uri, http_request)
end

#create_reward(reward_attributes) ⇒ Object



88
89
90
91
92
93
# File 'lib/electric_profile_ruby/client.rb', line 88

def create_reward(reward_attributes)
  uri = URI(@api_url + 'reward')
  http_request = Net::HTTP::Post.new uri, @http_headers
  http_request.body = { "data" => reward_attributes }.to_json
  perform_request(uri, http_request)
end

#fetch_profiler(profiler_id) ⇒ Object



54
55
56
57
58
# File 'lib/electric_profile_ruby/client.rb', line 54

def fetch_profiler(profiler_id)
  uri = URI(@api_url + 'profiler?id=' + profiler_id)
  http_request = Net::HTTP::Get.new uri, @http_headers
  perform_request(uri, http_request)
end

#fetch_profilers(page_size = 99999) ⇒ Object



48
49
50
51
52
# File 'lib/electric_profile_ruby/client.rb', line 48

def fetch_profilers(page_size = 99999)
  uri = URI(@api_url + "profiler?PageSize=#{page_size}")
  http_request = Net::HTTP::Get.new uri, @http_headers
  perform_request(uri, http_request)
end

#fetch_question(question_id) ⇒ Object



28
29
30
31
32
# File 'lib/electric_profile_ruby/client.rb', line 28

def fetch_question(question_id)
  uri = URI(@api_url + 'question?id=' + question_id)
  http_request = Net::HTTP::Get.new uri, @http_headers
  perform_request(uri, http_request)
end

#fetch_questions(page_size = 99999) ⇒ Object



22
23
24
25
26
# File 'lib/electric_profile_ruby/client.rb', line 22

def fetch_questions(page_size = 99999)
  uri = URI(@api_url + "question?PageSize=#{page_size}")
  http_request = Net::HTTP::Get.new uri, @http_headers
  perform_request(uri, http_request)
end

#fetch_respondent_profiler(profiler_id, user_id, locale) ⇒ Object

Raises:

  • (ArgumentError)


74
75
76
77
78
79
80
# File 'lib/electric_profile_ruby/client.rb', line 74

def fetch_respondent_profiler(profiler_id, user_id, locale)
  raise ArgumentError, 'Survey token is required' unless survey_token = ENV['ELECTRIC_PROFILE_SURVEY_TOKEN']
  @http_headers['Panel-Services-Auth-Token'] = survey_token
  uri = URI("#{@api_url}respondentProfiler?profilerId=#{profiler_id}&userId=#{user_id}&locale=#{locale}")
  http_request = Net::HTTP::Get.new uri, @http_headers
  perform_request(uri, http_request)
end

#fetch_reward(reward_id) ⇒ Object



82
83
84
85
86
# File 'lib/electric_profile_ruby/client.rb', line 82

def fetch_reward(reward_id)
  uri = URI(@api_url + 'reward?id=' + reward_id)
  http_request = Net::HTTP::Get.new uri, @http_headers
  perform_request(uri, http_request)
end

#queue_reward_delivery(reward_id) ⇒ Object

Raises:

  • (ArgumentError)


102
103
104
105
106
107
# File 'lib/electric_profile_ruby/client.rb', line 102

def queue_reward_delivery(reward_id)
  raise ArgumentError, 'Reward ID is required' unless reward_id
  uri = URI(@api_url + 'reward/' + reward_id + '/queueDelivery')
  http_request = Net::HTTP::Put.new uri, @http_headers
  perform_request(uri, http_request)
end

#update_profiler(profiler_attributes) ⇒ Object



67
68
69
70
71
72
# File 'lib/electric_profile_ruby/client.rb', line 67

def update_profiler(profiler_attributes)
  uri = URI(@api_url + 'profiler')
  http_request = Net::HTTP::Put.new uri, @http_headers
  http_request.body = { "data" => profiler_attributes }.to_json
  perform_request(uri, http_request)
end

#update_question(question_attributes) ⇒ Object



41
42
43
44
45
46
# File 'lib/electric_profile_ruby/client.rb', line 41

def update_question(question_attributes)
  uri = URI(@api_url + 'question')
  http_request = Net::HTTP::Put.new uri, @http_headers
  http_request.body = { "data" => question_attributes }.to_json
  perform_request(uri, http_request)
end

#update_reward(reward_attributes) ⇒ Object



95
96
97
98
99
100
# File 'lib/electric_profile_ruby/client.rb', line 95

def update_reward(reward_attributes)
  uri = URI(@api_url + 'reward')
  http_request = Net::HTTP::Put.new uri, @http_headers
  http_request.body = { "data" => reward_attributes }.to_json
  perform_request(uri, http_request)
end