Class: Gosquared::People
- Inherits:
-
Object
- Object
- Gosquared::People
- Defined in:
- lib/gosquared/people.rb
Constant Summary collapse
- BASEURL =
'https://api.gosquared.com/people/v1/'.freeze
- VERSION =
%w[v1 v2 v3].freeze
- DIMENSIONS =
%w[devices eventTypes people propertyTypes feed].freeze
- @@filters =
{ query: @query, filters: @filters, sort: @sort, format: @presenter, limit: @limit, type: @type, from: @from, to: @to }
Instance Method Summary collapse
- #check_for_nil_user ⇒ Object
- #delete ⇒ Object
- #fetch ⇒ Object
-
#initialize(api_key, site_token) ⇒ People
constructor
A new instance of People.
- #person_id(object, filter = nil) ⇒ Object
- #post ⇒ Object
- #smartgroups(group_id = nil, filter = nil) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(api_key, site_token) ⇒ People
Returns a new instance of People.
11 12 13 14 15 16 |
# File 'lib/gosquared/people.rb', line 11 def initialize(api_key, site_token) @site_token = site_token @api_key = api_key @person_id = '' @person_filter = '' end |
Instance Method Details
#check_for_nil_user ⇒ Object
82 83 84 85 86 87 |
# File 'lib/gosquared/people.rb', line 82 def check_for_nil_user if @data.key?(:person_id) && @data[:person_id].nil? @data.tap { |_data| @data.delete(:person_id) } warn 'person_id is nil, event will not be track against a user' end end |
#delete ⇒ Object
54 55 56 |
# File 'lib/gosquared/people.rb', line 54 def delete response = Client.new.delete(url) end |
#fetch ⇒ Object
48 49 50 51 52 |
# File 'lib/gosquared/people.rb', line 48 def fetch data = Client.new.get(url) @@filters.each { |key, _value| @@filters[key] = nil } if data data end |
#person_id(object, filter = nil) ⇒ Object
33 34 35 36 37 |
# File 'lib/gosquared/people.rb', line 33 def person_id(object, filter=nil) @person_id = '/' + object @person_filter = '/' + filter if filter self end |
#post ⇒ Object
75 76 77 78 79 80 |
# File 'lib/gosquared/people.rb', line 75 def post check_for_nil_user response = Client.new.post(url, @data) @data = nil if response.code === '200' response end |
#smartgroups(group_id = nil, filter = nil) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/gosquared/people.rb', line 39 def smartgroups(group_id = nil, filter = nil) if group_id @dimension = "smartgroups/#{group_id}/people" if filter == 'people' @dimension = "smartgroups/#{group_id}/count/latest" if filter == 'count' else @dimension = 'smartgroups' end self end |
#url ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gosquared/people.rb', line 58 def url array = [''] url = BASEURL + @dimension + @person_id + @person_filter + "?api_key=#{@api_key}" + "&site_token=#{@site_token}" @@filters.each do |key, value| if @dimension == 'people' && key == :filters && value.is_a?(Array) json_object = JSON.generate(value) filter_request = URI.escape(json_object, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) array << "#{key}=#{filter_request}" else array << "#{key}=#{value}" if value end end parameters = array.join('&') url.concat(parameters) end |