localytics-ruby 0.0.5 → 0.0.7

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
- SHA1:
3
- metadata.gz: d1b8a1d9ae1a451d98a7314093d977114d964193
4
- data.tar.gz: 40b171b4e40c8a38356c57fab6bc30006860d48a
2
+ SHA256:
3
+ metadata.gz: a6b2f7023c1d5e981f2bc4bb4ff10f9970cbc453cfe160102baa554a60a1c945
4
+ data.tar.gz: 65bbf127d9306b033efef67660e438365c5c1b6b2fda1e78fd3336745e520203
5
5
  SHA512:
6
- metadata.gz: a10bef510e7104b18ba3b9f4d23749f785c4f641f8058b3ecd213c5609546fbc6f4a1008aeba004c23d9e8c66c33dc1d34d341da19a9c26f2407e82498f65434
7
- data.tar.gz: 892283af6236abbfaf97c58dc2ddd4ee8366946d4d1bab87d799164c6ad4069c12f3dfa3e69bcfcdd8e2381257156862426b488d232cb86951eba963e834a5a7
6
+ metadata.gz: 80bd19ff995e8f0b9379ea6afbc9975ef6987f3a760c3b50858b71acb096dae0e17519fd0bd40ad8d596dea6553961252b830dccd7387eaa82cd8a8a03db8ca6
7
+ data.tar.gz: 65b7fc28afaa3545b508f7b7e4480a06c67309f0b4fa5c01ebaa69c300ab07d589183f73c63299cee501c62bde21df701f6cc4675dfd69d15ce4b684fa30613d
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tobuy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,38 @@
1
+ Tobuy
2
+ =====
3
+
4
+ Ruby wrapper for Localytics API
5
+
6
+ A lot of inspiration (and code) for how this gem was built come from https://github.com/Mango/mango-ruby
7
+
8
+
9
+ ## Description
10
+
11
+ API to interact with Localytics
12
+ https://localytics.com/
13
+
14
+
15
+ ## Installation
16
+
17
+ As usual, you can install it using rubygems.
18
+
19
+ ```
20
+ $ gem install localytics-ruby
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ require 'localytics-ruby'
27
+
28
+ Localytics.api_key = ENV['LOCALYTICS_API_KEY']
29
+ Localytics.api_secret = ENV['LOCALYTICS_API_SECRET']
30
+
31
+ customerId = 1
32
+
33
+ begin
34
+ profile = Localytics::Profile.show 1
35
+ rescue Localytics::Error => e
36
+ e.each {|code, message| ... }
37
+ end
38
+ ```
@@ -4,13 +4,14 @@ require 'base64'
4
4
  require_relative 'localytics/profile'
5
5
  require_relative 'localytics/push'
6
6
  require_relative 'localytics/app'
7
+ require_relative 'localytics/event'
7
8
 
8
9
  module Localytics
9
10
  class Error < StandardError
10
11
  include Enumerable
11
12
  attr_accessor :errors
12
13
 
13
- def initialize message, errors={}
14
+ def initialize(message, errors={})
14
15
  super message
15
16
  @errors = errors
16
17
  end
@@ -40,30 +41,37 @@ module Localytics
40
41
 
41
42
  unless method == :get
42
43
  payload = JSON.generate(params)
43
- params = nil
44
+ params = nil
44
45
  end
45
46
 
46
47
  auth = 'Basic ' + Base64.strict_encode64("#{api_key}:#{api_secret}")
47
48
 
48
49
  headers = {
49
- :params => params,
50
- :content_type => 'application/json',
51
- :accept => 'application/json',
50
+ :params => params,
51
+ :content_type => 'application/json',
52
+ :accept => 'application/json',
52
53
  :authorization => auth
53
54
 
54
55
  }.merge(headers)
55
56
 
56
57
  options = {
57
58
  :headers => headers,
58
- :method => method,
59
- :url => url,
59
+ :method => method,
60
+ :url => url,
60
61
  :payload => payload
61
62
  }
62
63
 
63
64
  begin
64
- response = execute_request(options)
65
- return {} if response.code == 204 and method == :delete
66
- JSON.parse(response.body, :symbolize_names => true)
65
+ return_hash = {}
66
+ response = execute_request(options)
67
+ return return_hash if response.code == 204 && method == :delete
68
+
69
+ if response.body && !response.body.empty?
70
+ # Don't try to call JSON.parse on empty response body.
71
+ return_hash = JSON.parse(response.body, :symbolize_names => true)
72
+ end
73
+ return return_hash
74
+
67
75
  rescue RestClient::Exception => e
68
76
  handle_errors e
69
77
  end
@@ -75,8 +83,8 @@ module Localytics
75
83
  RestClient::Request.execute(options)
76
84
  end
77
85
 
78
- def self.handle_errors exception
79
- body = JSON.parse exception.http_body
86
+ def self.handle_errors(exception)
87
+ body = JSON.parse(exception.http_body)
80
88
  raise Error.new(exception.to_s, body['errors'])
81
89
  end
82
90
 
@@ -0,0 +1,42 @@
1
+ module Localytics
2
+
3
+ class Event
4
+ class << self
5
+ attr_accessor :app_id
6
+ end
7
+
8
+ # @param event_attributes = Optional hash of up to 50 key/value attribute pairs.
9
+ # Values must be formatted as strings.
10
+ # @param ltv_change = Optional int representing incremental change in user's lifetime value.
11
+ # Must be integer, e.g. use 299 for $2.99.
12
+ def self.send(app_id, customer_id, event_name, event_attributes=nil, ltv_change=nil, api_key=nil, api_secret=nil)
13
+ raise Error.new('No APP id provided') unless app_id ||= self.app_id
14
+ raise Error.new('No customer_id provided') if customer_id.nil?
15
+ raise Error.new('No event_name provided') if event_name.nil? || event_name.empty?
16
+
17
+ params = {
18
+ schema_url: "https://localytics-files.s3.amazonaws.com/schemas/eventsApi/v1.json",
19
+ app_uuid: app_id,
20
+ customer_id: customer_id.to_s,
21
+ event_name: event_name,
22
+ event_time: (Time.now.to_f * 1000).to_i,
23
+ uuid: SecureRandom.uuid
24
+ }
25
+ params[:attributes] = event_attributes if event_attributes && !event_attributes.empty?
26
+ params[:ltv_change] = ltv_change if ltv_change
27
+
28
+ Localytics.request api_base, :post, url, api_key, api_secret, params
29
+ end
30
+
31
+ private
32
+
33
+ def self.api_base
34
+ "https://analytics.localytics.com/events/v1"
35
+ end
36
+
37
+ def self.url
38
+ "/uploads"
39
+ end
40
+ end
41
+
42
+ end
@@ -88,3 +88,9 @@ test 'show app attributes' do |mock|
88
88
  events = Localytics::App.app_attributes('umdois')
89
89
  assert_equal 'Clicked Link', events[:events][0][:event_name]
90
90
  end
91
+
92
+ test 'send event' do |mock|
93
+ mock.expects(:post).once.with('https://analytics.localytics.com/events/v1/uploads', anything).returns(test_response({}, 202))
94
+ response = Localytics::Event.send('app_id', 111111, 'event_name')
95
+ assert(response.empty?)
96
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localytics-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobuy development team
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-02 00:00:00.000000000 Z
12
+ date: 2020-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -43,14 +43,14 @@ dependencies:
43
43
  name: mocha
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - '='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '1.1'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - '='
54
54
  - !ruby/object:Gem::Version
55
55
  version: '1.1'
56
56
  description: API to interact with Localytics https://localytics.com/
@@ -60,9 +60,12 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
+ - LICENSE
64
+ - README.md
63
65
  - lib/localytics-ruby.rb
64
66
  - lib/localytics.rb
65
67
  - lib/localytics/app.rb
68
+ - lib/localytics/event.rb
66
69
  - lib/localytics/profile.rb
67
70
  - lib/localytics/push.rb
68
71
  - test/localytics_test.rb
@@ -86,11 +89,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
89
  - !ruby/object:Gem::Version
87
90
  version: '0'
88
91
  requirements: []
89
- rubyforge_project:
90
- rubygems_version: 2.4.5
92
+ rubygems_version: 3.0.8
91
93
  signing_key:
92
94
  specification_version: 4
93
95
  summary: Ruby wrapper for Localytics API
94
96
  test_files:
95
- - test/localytics_test.rb
96
97
  - test/test_helper.rb
98
+ - test/localytics_test.rb