fanforce 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/fanforce/main.rb CHANGED
@@ -4,10 +4,16 @@ require 'rest-client'
4
4
 
5
5
  class Fanforce
6
6
  include Fanforce::Utils
7
-
7
+ attr_reader :params
8
8
  ########################################################################
9
- def initialize(auth_data=nil)
10
- auth(auth_data) if is_present?(auth_data)
9
+ def initialize(params={})
10
+ add_params(params)
11
+ auth(@params) if @params.length > 0
12
+ end
13
+
14
+ def add_params(params)
15
+ @params ||= {}
16
+ @params.merge!(collect_known_params params)
11
17
  end
12
18
 
13
19
  def get(path, params={})
@@ -42,8 +48,8 @@ class Fanforce
42
48
 
43
49
  def delete(path, params={})
44
50
  url = complete_url(path)
45
- params = apply_auth(url)
46
- RestClient.delete(url, {:query => params, :accept => :json}) do |response, request, result, &block|
51
+ params = apply_auth(params)
52
+ RestClient.delete(url, {:params => params, :accept => :json}) do |response, request, result, &block|
47
53
  handle_response(response, request, url, params)
48
54
  end
49
55
  end
@@ -81,17 +87,16 @@ class Fanforce
81
87
  end
82
88
 
83
89
  def auth(auth_data=nil)
84
- if is_present?(auth_data)
85
- auth_data = auth_data.is_a?(Hash) ? auth_data.symbolize_keys : {api_key: auth_data.to_s}
86
- @auth_hash ||= {}
87
- @auth_hash[:api_key] = auth_data[:api_key] if is_present?(auth_data[:api_key])
88
- @auth_hash[:fanforce_id] = auth_data[:fanforce_id] if is_present?(auth_data[:fanforce_id])
89
- end
90
- @auth_hash
90
+ @auth_hash ||= {}
91
+ return @auth_hash if is_blank?(auth_data)
92
+ auth_data = auth_data.is_a?(Hash) ? auth_data.symbolize_keys : {api_key: auth_data.to_s}
93
+ @auth_hash.merge! remove_nil_values(api_key: auth_data[:api_key], fanforce_id: auth_data[:fanforce_id], fanforce_slug: auth_data[:fanforce_slug], app_id: auth_data[:app_id], module_id: auth_data[:module_id], behavior_id: auth_data[:behavior_id], widget_id: auth_data[:widget_id])
94
+ @params.merge!(@auth_hash)
95
+ valid_auth?
91
96
  end
92
97
 
93
98
  def valid_auth?
94
- is_present?(@auth_hash) and is_present?(@auth_hash[:api_key])
99
+ is_present?(@auth_hash) and is_present?(@auth_hash[:api_key]) and is_present?(@auth_hash[:fanforce_id])
95
100
  end
96
101
 
97
102
  def apply_auth(params)
@@ -12,20 +12,20 @@ module Fanforce::Utils
12
12
  !is_blank?(obj)
13
13
  end
14
14
 
15
- def valid_fanforce_js_request?(params)
15
+ def valid_fanforce_js_request?(params=@params)
16
16
  return false if !params.is_a?(Hash)
17
17
  return false if is_blank?(params[:fanforce_id]) or is_blank?(params[:api_key])
18
18
  return true
19
19
  end
20
20
 
21
- def valid_fanforce_request?(params)
21
+ def valid_fanforce_request?(params=@params)
22
22
  return false if !params.is_a?(Hash)
23
23
  return false if is_blank?(params[:fanforce_id])
24
24
  return false if is_blank?(params[:app_id]) and is_blank?(params[:behavior_id]) and is_blank?(params[:module_id]) and is_blank?(params[:widget_id])
25
25
  return true
26
26
  end
27
27
 
28
- def valid_install_request?(params)
28
+ def valid_install_request?(params=@params)
29
29
  return false if !params.is_a?(Hash)
30
30
  return false if is_blank?(params[:fanforce_id])
31
31
  return false if is_blank?(params[:app_id]) and is_blank?(params[:behavior_id]) and is_blank?(params[:module_id]) and is_blank?(params[:widget_id])
@@ -33,7 +33,7 @@ module Fanforce::Utils
33
33
  return true
34
34
  end
35
35
 
36
- def valid_uninstall_request?(params)
36
+ def valid_uninstall_request?(params=@params)
37
37
  return false if !params.is_a?(Hash)
38
38
  return false if is_blank?(params[:fanforce_id])
39
39
  return false if is_blank?(params[:app_id]) and is_blank?(params[:behavior_id]) and is_blank?(params[:module_id]) and is_blank?(params[:widget_id])
@@ -41,7 +41,11 @@ module Fanforce::Utils
41
41
  return true
42
42
  end
43
43
 
44
- def parse_params(params)
44
+ def remove_nil_values(hash)
45
+ hash.delete_if {|k,v| v.nil? }
46
+ end
47
+
48
+ def collect_known_params(params)
45
49
  if is_present?(params[:app_id])
46
50
  plugin_type = :app
47
51
  plugin_id = params[:app_id]
@@ -55,7 +59,15 @@ module Fanforce::Utils
55
59
  plugin_type = :widget
56
60
  plugin_id = params[:widget_id]
57
61
  end
58
- {:"#{plugin_type}_id" => params["#{plugin_type}_id"], plugin_type: plugin_type, plugin_id: plugin_id, fanforce_id: params[:fanforce_id], api_key: params[:api_key]}
62
+ remove_nil_values(:"#{plugin_type}_id" => params["#{plugin_type}_id"], plugin_type: plugin_type, plugin_id: plugin_id, fanforce_id: params[:fanforce_id], fanforce_slug: params[:fanforce_slug], api_key: params[:api_key])
63
+ end
64
+
65
+ def remove_internal_params(params)
66
+ params.delete_if { |k,v| [:app_id, :behavior_id, :module_id, :widget_id, :plugin_type, :plugin_id, :fanforce_id, :fanforce_slug, :api_key].include? k }
67
+ end
68
+
69
+ def remove_sensitive_params(params)
70
+ params.delete_if { |k,v| [:api_key].include? k }
59
71
  end
60
72
 
61
73
  def parse_url(raw_url)
@@ -1,3 +1,3 @@
1
1
  class Fanforce
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fanforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: