Class: WidgetService

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

Constant Summary collapse

@@create_widget_url =
'https://showoff-rails-react-production.herokuapp.com/api/v1/widgets'
@@update_destroy_widget_url =
'https://showoff-rails-react-production.herokuapp.com/api/v1/widgets/'
@@list_widget_url =
'https://showoff-rails-react-production.herokuapp.com/api/v1/widgets/visible'

Class Method Summary collapse

Class Method Details

.create_widget(widget, bearer_token) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/services/widget_service.rb', line 13

def self.create_widget(widget, bearer_token)
    widget_data = get_widget(widget)
    create_widget_payload = Widget.get_payload(widget_data)
    return RestClient::Request.execute(method: :post, url: @@create_widget_url,
        payload: create_widget_payload,
        headers: {'Content-Type': 'application/json', 'Authorization': bearer_token})
end

.destroy_widget(widget_id, bearer_token) ⇒ Object



30
31
32
33
34
# File 'lib/services/widget_service.rb', line 30

def self.destroy_widget(widget_id, bearer_token)
    destroy_url_with_widget_id = @@update_destroy_widget_url + "#{widget_id}"
    return RestClient::Request.execute(method: :delete, url: destroy_url_with_widget_id,
        headers: {'Content-Type': 'application/json', 'Authorization': bearer_token})
end

.get_private_widgets(bearer_token) ⇒ Object



36
37
38
39
# File 'lib/services/widget_service.rb', line 36

def self.get_private_widgets(bearer_token)
    return RestClient::Request.execute(method: :get, url: @@create_widget_url,
        headers: {'Content-Type': 'application/json', 'Authorization': bearer_token})
end

.get_public_widgets(bearer_token) ⇒ Object



41
42
43
44
45
# File 'lib/services/widget_service.rb', line 41

def self.get_public_widgets(bearer_token)
    return RestClient::Request.execute(method: :get, url: @@list_widget_url, 
        headers: {'Content-Type': 'application/json', params: {:client_id => ApplicationConfig.get_client_id, :client_secret => ApplicationConfig.get_client_secret}, 
        'Authorization': bearer_token})
end

.get_public_widgets_with_search_term(search_term, bearer_token) ⇒ Object



47
48
49
50
51
# File 'lib/services/widget_service.rb', line 47

def self.get_public_widgets_with_search_term(search_term, bearer_token)
    return RestClient::Request.execute(method: :get, url: @@list_widget_url, 
        headers: {'Content-Type': 'application/json', params: {:client_id => ApplicationConfig.get_client_id, :client_secret => ApplicationConfig.get_client_secret, :term => search_term}, 
        'Authorization': bearer_token})
end

.get_widget(widget) ⇒ Object



53
54
55
56
57
# File 'lib/services/widget_service.rb', line 53

def self.get_widget(widget)
    widget_data = WidgetBase.new
    widget_data.widget = widget 
    return widget_data
end

.update_widget(widget, widget_id, bearer_token) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/services/widget_service.rb', line 21

def self.update_widget(widget, widget_id, bearer_token)
    update_url_with_widget_id = @@update_destroy_widget_url + "#{widget_id}"
    widget_data = get_widget(widget)
    update_widget_payload = Widget.get_payload(widget_data)
    return RestClient::Request.execute(method: :put, url: update_url_with_widget_id,
        payload: update_widget_payload,
        headers: {'Content-Type': 'application/json', 'Authorization': bearer_token})
end