pirsch_api 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/pirsch_api/client.rb +17 -16
  4. data/lib/pirsch_api/error.rb +1 -1
  5. data/lib/pirsch_api/object.rb +1 -1
  6. data/lib/pirsch_api/objects/active.rb +1 -1
  7. data/lib/pirsch_api/objects/domain.rb +1 -1
  8. data/lib/pirsch_api/objects/duration_page.rb +1 -1
  9. data/lib/pirsch_api/objects/duration_session.rb +1 -1
  10. data/lib/pirsch_api/objects/event.rb +1 -1
  11. data/lib/pirsch_api/objects/growth.rb +1 -1
  12. data/lib/pirsch_api/objects/page.rb +1 -1
  13. data/lib/pirsch_api/objects/referrer.rb +1 -1
  14. data/lib/pirsch_api/objects/token.rb +1 -1
  15. data/lib/pirsch_api/objects/utm_campaign.rb +1 -1
  16. data/lib/pirsch_api/objects/utm_medium.rb +1 -1
  17. data/lib/pirsch_api/objects/utm_source.rb +1 -1
  18. data/lib/pirsch_api/objects/visitor.rb +1 -1
  19. data/lib/pirsch_api/resources/base.rb +7 -8
  20. data/lib/pirsch_api/resources/domain.rb +2 -2
  21. data/lib/pirsch_api/resources/statistics/active.rb +1 -1
  22. data/lib/pirsch_api/resources/statistics/duration_page.rb +3 -3
  23. data/lib/pirsch_api/resources/statistics/duration_session.rb +3 -3
  24. data/lib/pirsch_api/resources/statistics/event.rb +3 -2
  25. data/lib/pirsch_api/resources/statistics/growth.rb +1 -1
  26. data/lib/pirsch_api/resources/statistics/page.rb +2 -2
  27. data/lib/pirsch_api/resources/statistics/referrer.rb +2 -2
  28. data/lib/pirsch_api/resources/statistics/utm_campaign.rb +3 -3
  29. data/lib/pirsch_api/resources/statistics/utm_medium.rb +3 -3
  30. data/lib/pirsch_api/resources/statistics/utm_source.rb +3 -3
  31. data/lib/pirsch_api/resources/statistics/visitor.rb +2 -2
  32. data/lib/pirsch_api/resources/token.rb +7 -9
  33. data/lib/pirsch_api/version.rb +1 -1
  34. data/lib/pirsch_api.rb +2 -2
  35. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e82d43aa436f9f1d2947ecf55d73e236bcaf002cc6a1b706d5e3cea589d6b69b
4
- data.tar.gz: a5e777c6d97f42df2b332f28cd72530470b4a192ae8c3c70655deaa41bfd70d8
3
+ metadata.gz: 006765cdfc16afa484a20da5b5e7e507dc50a5fe41e7cf6a869199d9d3112241
4
+ data.tar.gz: adf718d65c7d1f74a0b3f48a2803b778dc15d58c0b2f38e7730dc387e7f076a0
5
5
  SHA512:
6
- metadata.gz: 9ba33c184b234b4724f41dc1e3739bfe380ecb087e356fae99ca405ec1592dc2b0e1cfec607ffe8dc1631ddbb7c5a8f0ff312ff64f6262541302611034038bce
7
- data.tar.gz: 2f10015e504aad54aa4abba5719147fc7946870bc533b9dc97f0c1e1dc3342f8e6a469ef317f35dd7a2a016f8e2cc70d98c3c954a6268a67de5f06f40ddfe2f7
6
+ metadata.gz: ec39210e5901821c896b82c6a0f551adbfc541bd007403f7ef91c8147abebc67e75408ce7d691b530226a7a118753c290f0903960e18aaafdab4f7be0ec17285
7
+ data.tar.gz: fe077953f1d9a7ca5b69a945688e37ae8d0dcffcd158ca4b46e0fca1940a38580bd8686599b322c027adfba5298e2b4b4dcfd4c773a7356927b65c0e27140134
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pirsch_api (0.0.5)
4
+ pirsch_api (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -2,16 +2,17 @@
2
2
 
3
3
  module PirschApi
4
4
  class Client
5
-
6
- BASE_URL = 'https://api.pirsch.io/api/v1'
5
+ BASE_URL = "https://api.pirsch.io/api/v1"
7
6
 
8
7
  def initialize(client_id:, client_secret:)
9
- @client_id = client_id.to_s
8
+ @client_id = client_id.to_s
10
9
  @client_secret = client_secret.to_s
11
10
  end
12
11
 
13
12
  def valid?
14
- true if token rescue false
13
+ true if token
14
+ rescue
15
+ false
15
16
  end
16
17
 
17
18
  def token
@@ -22,48 +23,48 @@ module PirschApi
22
23
  DomainResource.new(client: self).run
23
24
  end
24
25
 
25
- def visitors(filters: {}, domain:)
26
+ def visitors(domain:, filters: {})
26
27
  VisitorResource.new(client: self, filters: filters, domain: domain).run
27
28
  end
28
29
 
29
- def pages(filters: {}, domain:)
30
+ def pages(domain:, filters: {})
30
31
  PageResource.new(client: self, filters: filters, domain: domain).run
31
32
  end
32
33
 
33
- def referrers(filters: {}, domain:)
34
+ def referrers(domain:, filters: {})
34
35
  ReferrerResource.new(client: self, filters: filters, domain: domain).run
35
36
  end
36
37
 
37
- def active(filters: {}, domain:)
38
+ def active(domain:, filters: {})
38
39
  ActiveResource.new(client: self, filters: filters, domain: domain).run
39
40
  end
40
41
 
41
- def growth(filters: {}, domain:)
42
+ def growth(domain:, filters: {})
42
43
  GrowthResource.new(client: self, filters: filters, domain: domain).run
43
44
  end
44
45
 
45
- def events(filters: {}, domain:)
46
+ def events(domain:, filters: {})
46
47
  EventResource.new(client: self, filters: filters, domain: domain).run
47
48
  end
48
49
 
49
- def utm_source(filters: {}, domain:)
50
+ def utm_source(domain:, filters: {})
50
51
  UtmSourceResource.new(client: self, filters: filters, domain: domain).run
51
52
  end
52
53
 
53
- def utm_medium(filters: {}, domain:)
54
+ def utm_medium(domain:, filters: {})
54
55
  UtmMediumResource.new(client: self, filters: filters, domain: domain).run
55
56
  end
56
57
 
57
- def utm_campaign(filters: {}, domain:)
58
+ def utm_campaign(domain:, filters: {})
58
59
  UtmCampaignResource.new(client: self, filters: filters, domain: domain).run
59
60
  end
60
61
 
61
- def duration_session(filters: {}, domain:)
62
+ def duration_session(domain:, filters: {})
62
63
  DurationSessionResource.new(client: self, filters: filters, domain: domain).run
63
64
  end
64
65
 
65
- def duration_page(filters: {}, domain:)
66
+ def duration_page(domain:, filters: {})
66
67
  DurationPageResource.new(client: self, filters: filters, domain: domain).run
67
68
  end
68
69
  end
69
- end
70
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class Error < StandardError
3
3
  end
4
- end
4
+ end
@@ -16,4 +16,4 @@ module PirschApi
16
16
  end
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class Active < Object
3
3
  end
4
- end
4
+ end
@@ -4,4 +4,4 @@ module PirschApi
4
4
  id.to_s
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class DurationPage < Object
3
3
  end
4
- end
4
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class DurationSession < Object
3
3
  end
4
- end
4
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class Event < Object
3
3
  end
4
- end
4
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class Growth < Object
3
3
  end
4
- end
4
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class Page < Object
3
3
  end
4
- end
4
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class Referrer < Object
3
3
  end
4
- end
4
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class Token < Object
3
3
  end
4
- end
4
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class UtmCampaign < Object
3
3
  end
4
- end
4
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class UtmMedium < Object
3
3
  end
4
- end
4
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class UtmSource < Object
3
3
  end
4
- end
4
+ end
@@ -1,4 +1,4 @@
1
1
  module PirschApi
2
2
  class Visitor < Object
3
3
  end
4
- end
4
+ end
@@ -1,6 +1,5 @@
1
1
  module PirschApi
2
2
  class BaseResource
3
-
4
3
  attr_accessor :client, :filters, :domain
5
4
 
6
5
  def initialize(client:, domain: nil, filters: {})
@@ -19,7 +18,7 @@ module PirschApi
19
18
  end
20
19
 
21
20
  def errors
22
- @errors[:client] = 'client is invalid' unless client.valid?
21
+ @errors[:client] = "client is invalid" unless client.valid?
23
22
  @errors
24
23
  end
25
24
 
@@ -29,24 +28,24 @@ module PirschApi
29
28
 
30
29
  def run
31
30
  raise PirschApi::Error.new errors unless valid?
32
-
31
+
33
32
  if domain
34
33
  filters[:id] = domain.to_s
35
34
  end
36
35
 
37
36
  url = "#{PirschApi::Client::BASE_URL}/#{request_url}"
38
- url << "?#{filters.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&") }" if filters.any?
37
+ url << "?#{filters.to_a.map { |x| "#{x[0]}=#{CGI.escape(x[1])}" }.join("&")}" if filters.any?
39
38
 
40
39
  puts "[Pirsch API] run #{url}"
41
40
 
42
41
  uri = URI.parse url
43
42
 
44
43
  req = Net::HTTP::Get.new(uri.request_uri)
45
- req.add_field('Authorization', "Bearer #{client.token.access_token}")
44
+ req.add_field("Authorization", "Bearer #{client.token.access_token}")
46
45
 
47
46
  http = Net::HTTP.new(uri.host, uri.port)
48
- http.use_ssl = true
49
-
47
+ http.use_ssl = true
48
+
50
49
  response = http.request(req)
51
50
  raise PirschApi::Error.new "Api request failed (#{response.body})" unless response.code == "200"
52
51
  raise PirschApi::Error.new "Api request returned nil (#{response.body})" if response.body.nil?
@@ -54,4 +53,4 @@ module PirschApi
54
53
  parse_response response.body
55
54
  end
56
55
  end
57
- end
56
+ end
@@ -5,7 +5,7 @@ module PirschApi
5
5
  end
6
6
 
7
7
  def parse_response(body)
8
- JSON.parse(body).map{ |o| Domain.new o }
8
+ JSON.parse(body).map { |o| Domain.new o }
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -8,4 +8,4 @@ module PirschApi
8
8
  Active.new JSON.parse(body)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -3,9 +3,9 @@ module PirschApi
3
3
  def request_url
4
4
  "statistics/duration/page"
5
5
  end
6
-
6
+
7
7
  def parse_response(body)
8
- JSON.parse(body)&.map{ |o| DurationPage.new o }
8
+ JSON.parse(body)&.map { |o| DurationPage.new o }
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -3,9 +3,9 @@ module PirschApi
3
3
  def request_url
4
4
  "statistics/duration/session"
5
5
  end
6
-
6
+
7
7
  def parse_response(body)
8
- JSON.parse(body)&.map{ |o| DurationSession.new o }
8
+ JSON.parse(body)&.map { |o| DurationSession.new o }
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -3,8 +3,9 @@ module PirschApi
3
3
  def request_url
4
4
  "statistics/events"
5
5
  end
6
+
6
7
  def parse_response(body)
7
- JSON.parse(body)&.map{ |o| Event.new o }
8
+ JSON.parse(body)&.map { |o| Event.new o }
8
9
  end
9
10
  end
10
- end
11
+ end
@@ -8,4 +8,4 @@ module PirschApi
8
8
  Growth.new JSON.parse(body)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -5,7 +5,7 @@ module PirschApi
5
5
  end
6
6
 
7
7
  def parse_response(body)
8
- JSON.parse(body)&.map{ |o| Page.new o }
8
+ JSON.parse(body)&.map { |o| Page.new o }
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -5,7 +5,7 @@ module PirschApi
5
5
  end
6
6
 
7
7
  def parse_response(body)
8
- JSON.parse(body)&.map{ |o| Referrer.new o }
8
+ JSON.parse(body)&.map { |o| Referrer.new o }
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -3,9 +3,9 @@ module PirschApi
3
3
  def request_url
4
4
  "statistics/utm/campaign"
5
5
  end
6
-
6
+
7
7
  def parse_response(body)
8
- JSON.parse(body)&.map{ |o| UtmCampaign.new o }
8
+ JSON.parse(body)&.map { |o| UtmCampaign.new o }
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -3,9 +3,9 @@ module PirschApi
3
3
  def request_url
4
4
  "statistics/utm/medium"
5
5
  end
6
-
6
+
7
7
  def parse_response(body)
8
- JSON.parse(body)&.map{ |o| UtmMedium.new o }
8
+ JSON.parse(body)&.map { |o| UtmMedium.new o }
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -3,9 +3,9 @@ module PirschApi
3
3
  def request_url
4
4
  "statistics/utm/source"
5
5
  end
6
-
6
+
7
7
  def parse_response(body)
8
- JSON.parse(body)&.map{ |o| UtmSource.new o }
8
+ JSON.parse(body)&.map { |o| UtmSource.new o }
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -5,7 +5,7 @@ module PirschApi
5
5
  end
6
6
 
7
7
  def parse_response(body)
8
- JSON.parse(body)&.map{ |o| Visitor.new o }
8
+ JSON.parse(body)&.map { |o| Visitor.new o }
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -1,12 +1,10 @@
1
1
  module PirschApi
2
-
3
2
  class TokenResource
4
-
5
3
  def initialize(client_id, client_secret)
6
- @client_id = client_id
4
+ @client_id = client_id
7
5
  @client_secret = client_secret
8
6
  end
9
-
7
+
10
8
  def request_url
11
9
  "token"
12
10
  end
@@ -29,16 +27,16 @@ module PirschApi
29
27
  http = Net::HTTP.new(uri.host, uri.port)
30
28
  http.use_ssl = true
31
29
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
32
-
33
- header = { 'Content-Type': 'text/json' }
30
+
31
+ header = {"Content-Type": "text/json"}
34
32
  request = Net::HTTP::Post.new(uri.request_uri, header)
35
33
  request.body = request_body
36
-
34
+
37
35
  response = http.request(request)
38
36
 
39
37
  raise Error.new "Token request failed. (#{response.body})" unless response.code == "200"
40
-
38
+
41
39
  parse_response(response.body)
42
40
  end
43
41
  end
44
- end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module PirschApi
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/pirsch_api.rb CHANGED
@@ -1,9 +1,9 @@
1
- require 'json'
1
+ require "json"
2
2
  require "net/http"
3
3
  require "uri"
4
4
  require "cgi"
5
5
 
6
- require 'pirsch_api/version'
6
+ require "pirsch_api/version"
7
7
 
8
8
  module PirschApi
9
9
  autoload :Client, "pirsch_api/client"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pirsch_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Garcia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-16 00:00:00.000000000 Z
11
+ date: 2023-06-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A very humble wrapper for the API by Pirsch.io
14
14
  email:
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  requirements: []
84
- rubygems_version: 3.1.4
84
+ rubygems_version: 3.3.7
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: A simple Pirsch Analytics API wrapper for Rails