gosquared 3.0.3 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78358a00b7bf496eef23fa1b7dacbb2f1e1096e1
4
- data.tar.gz: dd61d41cf61c67bf9ec5c505335448e792af6c67
3
+ metadata.gz: 190af14d102193d71cd19ee272100216f2192fae
4
+ data.tar.gz: d736e2f7d7fc41c69e98628fe6886144f00e2744
5
5
  SHA512:
6
- metadata.gz: 38f86d39c694124b9f2e517cb7e12e74dc20c32b91010852da37951957cbd79b04e766029a04fb8319c17b9581b030807d744e1747447e7e6ff7aaa84aa9c4f0
7
- data.tar.gz: 868a7cb63f24a03d094c19f87245caa2e749455dfd638c9f8e3caf86284a609c363f1d105b841aa7fe33846290f2cdd745fa965095f1fb667616a57a5be46fb9
6
+ metadata.gz: 6f050ba2156fb41fe186a622b04162446b0eb80de08b47617a89ed7babfad4b16ebf4d7e5572f4670dc7712387fad73c9bb04d526f3a0c7ea9c7d25bdf15fc87
7
+ data.tar.gz: a8393ddb2aa97c3a116a6270423f6fba3c880f3646927ce545e9faf60c73b7f120fedc4e725fefa82f20b875798152b14ada071571740d2207d8f71aa5fccaf7
data/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/gosquared/ruby-client.svg?branch=master)](https://travis-ci.org/gosquared/ruby-gem)
4
4
 
5
- **This is an early beta, please open an issue if you find anything not working, or to leave feedback for improvement. You can also get in touch directly: russell@gosquared.com**
5
+ **Please feel free to open an issue if you find anything not working, or to leave feedback for improvement. You can also get in touch directly: russell@gosquared.com**
6
6
 
7
7
  This gems works with the [GoSquared API](https://www.gosquared.com/docs/api/), You can use it for both fetching metrics from your GoSquared account and also posting new events and contacts.
8
8
 
9
- Note, if you are looking to set up GoSquared for the first time and install Analytics, People and Live Chat within a Rails app, you can do so by using our [GoSquared-Rails gem]
9
+ **Note:** if you are looking to set up GoSquared for the first time and install Analytics, People CRM and Live Chat within a Rails app, you can do so by using our [GoSquared-Rails gem]
10
10
  (https://github.com/gosquared/gosquared-rails)
11
11
 
12
12
  All functions listed in the API documentation are methods you can call on the GoSquared class.
@@ -9,12 +9,11 @@ module Gosquared
9
9
  @@filters = {query: @query, filters: @filters, sort: @sort,
10
10
  format: @presenter, limit: @limit, type: @type, from: @from, to: @to}
11
11
 
12
- def initialize(api_key, site_token, client = Gosquared::Client.new)
12
+ def initialize(api_key, site_token)
13
13
  @site_token = site_token
14
14
  @api_key = api_key
15
15
  @person_id = ""
16
16
  @person_filter = ""
17
- @client = client
18
17
  end
19
18
 
20
19
  DIMENSIONS.each do |dimension|
@@ -28,30 +27,54 @@ module Gosquared
28
27
  @@filters.each do |key, value|
29
28
  define_method key do |argument|
30
29
  @@filters[key] = argument
31
- self
32
- end
33
- end
30
+ puts @@filters[key]
31
+ self
32
+ end
33
+ end
34
34
 
35
- def person_id(object, filter)
36
- @person_id = "/" + object
37
- @person_filter = "/" + filter
38
- self
39
- end
35
+ def person_id(object, filter)
36
+ @person_id = "/" + object
37
+ @person_filter = "/" + filter
38
+ self
39
+ end
40
40
 
41
- def fetch
42
- data = @client.get(url)
43
- @@filters.each{|key, value| @@filters[key]=nil} if data
44
- data
45
- end
41
+ def fetch
42
+ data = Client.new.get(url)
43
+ @@filters.each{|key, value| @@filters[key]=nil} if data
44
+ data
45
+ end
46
46
 
47
- def url
48
- array = [""]
49
- url = BASEURL + @dimension + @person_id + @person_filter +
50
- "?api_key=#{@api_key}" + "&site_token=#{@site_token}"
51
- @@filters.each { |key, value| array << "#{key}=#{value}" if value }
52
- parameters=array.join('&')
53
- url.concat(parameters)
54
- end
47
+ def url
48
+ array = [""]
49
+ url = BASEURL + @dimension + @person_id + @person_filter +
50
+ "?api_key=#{@api_key}" + "&site_token=#{@site_token}"
51
+ @@filters.each do |key, value|
52
+ if @dimension=="people" && key == :filters && value.is_a?(Array)
53
+ json_object=JSON.generate(value)
54
+ filter_request=URI.escape(json_object, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
55
+ array << "#{key}=#{filter_request}"
56
+ else
57
+ array << "#{key}=#{value}" if value
58
+ end
59
+ end
60
+ parameters=array.join('&')
61
+ url.concat(parameters)
62
+ end
63
+
64
+ def post
65
+ puts @data
66
+ check_for_nil_user
67
+ response = Client.new.post(url, @data)
68
+ @data = nil if response.code === '200'
69
+ response
70
+ end
71
+
72
+ def check_for_nil_user
73
+ if @data.key?(:person_id) && @data[:person_id] == nil
74
+ @data.tap { |data| @data.delete(:person_id) }
75
+ warn 'person_id is nil, event will not be track against a user'
76
+ end
77
+ end
55
78
 
56
- end
79
+ end
57
80
  end
@@ -13,6 +13,7 @@ describe Gosquared::People do
13
13
 
14
14
  Gosquared::People::DIMENSIONS.each do |dimension|
15
15
  it "fetches a request from the GoSquared People API with #{dimension} dimension" do
16
+ next if dimension == "people"
16
17
  gs.send "#{dimension}"
17
18
  expect(gs.fetch).to eq("a" => [{"test"=>"response"}])
18
19
  end
@@ -47,5 +48,36 @@ describe Gosquared::People do
47
48
  end
48
49
  end
49
50
 
51
+ before do
52
+ data = '{"a": [{"test": "response"}, {"with": "filters"}]}'
53
+ stub_request(:get, "https://api.gosquared.com/people/v1/people?api_key=demo&filters=%5B%7B%22key%22:%22property%22,%22path%22:%22last.location.city%22,%22operator%22:%22contains%22,%22value%22:%22london%22%7D,%7B%22key%22:%22and%22,%22filters%22:%5B%7B%22key%22:%22property%22,%22path%22:%22totals.visits%22,%22operator%22:%22%3E%22,%22value%22:%221000%22%7D%5D%7D%5D&site_token=GSN-106863-S").
54
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'api.gosquared.com', 'User-Agent'=>'Ruby'}).
55
+ to_return(:status => 200, :body => data, :headers => {})
56
+ end
57
+
58
+ it "fetches a request from the GoSquared People API with filtering on properties" do
59
+ array=[
60
+ {
61
+ key: "property",
62
+ path: "last.location.city",
63
+ operator: "contains",
64
+ value: "london"
65
+ },
66
+ {
67
+ key: "and",
68
+ filters: [
69
+ {
70
+ "key": "property",
71
+ "path": "totals.visits",
72
+ "operator": ">",
73
+ "value": "1000"
74
+ }
75
+ ]
76
+ }
77
+ ]
78
+ gs.people.people.filters(array)
79
+ expect(gs.fetch).to eq("a" => [{"test"=>"response"}, {"with"=>"filters"}])
80
+ end
50
81
 
51
- end
82
+
83
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosquared
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Vaughan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-04 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubyforge_project:
87
- rubygems_version: 2.4.8
87
+ rubygems_version: 2.6.6
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: GoSquared Ruby Library