Class: Sorenson::Services::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sorenson/services/base.rb

Direct Known Subclasses

Account, Asset, Category, Event, Flag, Group, Metric, Preset, RatePlan, Site, Subaccount, Tag

Class Method Summary collapse

Class Method Details

.delete_from(url) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/sorenson/services/base.rb', line 53

def self.delete_from(url)
  
  delete_from_url = host + url
  client          = RestClient::Resource.new(delete_from_url, :user => , :password => )
  
  parse_response(client.delete)
end

.get_from(url, payload = {}) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/sorenson/services/base.rb', line 37

def self.get_from(url, payload = {})
  
  get_from_url = host + url + "?#{payload.to_query}"
  client       = RestClient::Resource.new(get_from_url, :user => , :password => )
  
  parse_response(client.get)
end

.hostObject



25
26
27
# File 'lib/sorenson/services/base.rb', line 25

def self.host
  ((ENV['360LOCAL'].to_s.upcase == 'TRUE' &&  ENV['RAILS_ENV'] == 'development') || ['test', 'cucumber'].include?(ENV['RAILS_ENV'])) ? 'http://localhost:3001' : 'http://360services.sorensonmedia.com'
end

.login_no_resource(username, password) ⇒ Object



21
22
23
# File 'lib/sorenson/services/base.rb', line 21

def self.(username, password)
  RestClient.post(host + "/sessions", :username => username, :password => password).body
end

.parse_response(response) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sorenson/services/base.rb', line 61

def self.parse_response(response)
  begin
    data = JSON.parse(response.body)
    if data.is_a?(Hash)
      HashWithIndifferentAccess.new.merge(data)
    else
      data
    end
  rescue JSON::ParserError => e
    raise InvalidServerResponse.new("Sorenson::Services::InvalidServerResponse: #{e.message}")
  end
end

.post_to(url, payload = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/sorenson/services/base.rb', line 29

def self.post_to(url, payload = {})
  
  post_to_url  = host + url
  client       = RestClient::Resource.new(post_to_url, :user => , :password => )
  
  parse_response(client.post(payload))
end

.put_to(url, payload = {}) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/sorenson/services/base.rb', line 45

def self.put_to(url, payload = {})
  
  put_to_url = host + url
  client     = RestClient::Resource.new(put_to_url, :user => , :password => )
  
  parse_response(client.put(payload))
end

.verify_account_settingsObject



15
16
17
18
19
# File 'lib/sorenson/services/base.rb', line 15

def self.
  if @@account_id.blank? || @@account_token.blank?
    raise Invalid360ServiceSetup.new("You must specify an account_id and account_token before using 360 services")
  end        
end