dito 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a5586a032255652b802a1b879e712d7e1bb03ebf
4
+ data.tar.gz: 68b68d9bac75b9aa1af029b78a4ad75e327ca0e9
5
+ SHA512:
6
+ metadata.gz: e7f253467c2dc4fc2eced2efa5c52db457f5d2cd955d54c08d5577c37fdc8e46cd739e45c85eda87f48d9b24e9d04ef73b4ed10e0033843ed25616696a412943
7
+ data.tar.gz: 65531263f7bc5e11530e5d1d5f7ea0aecc006141c890ea35df28a7b2f01001cd42cb904bc5b030cba85073d1ffe343c4052fee0cb2e081e86e7c360bfa89e1d5
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dito.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Marcos Nogueira
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # Dito
2
+
3
+ Essa gem tem como objetivo automatizar a integração com a Rest API da Dito.
4
+
5
+ ## Instalação
6
+
7
+ Adicione a linha abaixo no arquivo ``Gemfile`` da sua aplicação:
8
+
9
+ gem 'dito'
10
+
11
+ Execute:
12
+
13
+ $ bundle
14
+
15
+ Ou instale manualmente:
16
+
17
+ $ gem install dito
18
+
19
+ ## Uso
20
+
21
+ ### Configurando sua aplicação
22
+
23
+ Adicione o código abaixo em cada ambiente de configuração da sua aplicação.
24
+
25
+ Dito.configure do |c|
26
+ c.api_key = 'SUA_API_KEY'
27
+ c.secret = 'SUA_SECRET'
28
+ end
29
+
30
+ As chaves da sua aplicação podem ser encontradas na área de configuração do seu aplicativo na plataforma da Dito.
31
+
32
+ ### Enviando seus usuários
33
+
34
+ O método ``Dito.identify`` é usado para enviar os usuários da sua aplicação para a plataforma da Dito.
35
+
36
+ O nó data é reservado para as informações do usuários relativas a sua aplicação. Fique a vontade para enviar quantas informações quiser.
37
+
38
+ Exemplo:
39
+
40
+ Dito.identify({
41
+ id: Digest::SHA1.hexdigest('marcos.nogueira@dito.com.br'),
42
+ name: 'Marcos Nogueira',
43
+ email: 'marcos.nogueira@dito.com.br'
44
+ })
45
+
46
+ # Ou
47
+
48
+ Dito.identify({
49
+ facebook_id: '123141312312',
50
+ access_token: 'XXXXXXXXXX',
51
+ data: {
52
+ cpf: '101.032.076-95',
53
+ cargo: 'Desenvolvedor'
54
+ }
55
+ })
56
+
57
+ ### Criando eventos
58
+
59
+ O método ``Dito.track`` é usado para trackear o comportamento dos usuários na forma de eventos em sua aplicação.
60
+
61
+ O nó data é reservado para as informações do evento. Fique a vontade para enviar quantas informações quiser.
62
+
63
+ Exemplo:
64
+
65
+ Dito.track({
66
+ id: Digest::SHA1.hexdigest('marcos.nogueira@dito.com.br'),
67
+ event: {
68
+ action: 'nome-do-evento',
69
+ revenue: 5.99, // Opcional
70
+ data: {
71
+ propriedade_1: 'valor da propriedade 1',
72
+ propriedade_2: 'valor da propriedade 2'
73
+ }
74
+ }
75
+ })
76
+
77
+ ## Contributing
78
+
79
+ 1. Fork it ( http://github.com/<my-github-username>/dito/fork )
80
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
81
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
82
+ 4. Push to the branch (`git push origin my-new-feature`)
83
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/dito.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'dito/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "dito"
9
+ spec.version = Dito::VERSION
10
+ spec.authors = ["Marcos Nogueira"]
11
+ spec.email = ["marcos.nogueira@dito.com.br"]
12
+ spec.summary = %q{Gem para integração com a plataforma da Dito}
13
+ spec.description = %q{Essa gem tem como objetivo automatizar a integração com a Rest API da Dito.}
14
+ spec.homepage = "http://dito.com.br/"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_runtime_dependency "faraday"
25
+ spec.add_runtime_dependency "faraday_middleware"
26
+ end
data/dito.pem ADDED
@@ -0,0 +1,5 @@
1
+ -----BEGIN RSA PUBLIC KEY-----
2
+ MIGJAoGBALt2P6Ra1KTzVqxEaS29WvQtaiBOecuL8P/MOd1Ik8EBMteRJSZX86nE
3
+ ymGrUXySAjyvtRpj6nR0yOIyZyQo3ZWCcdmIsPQ/xfaDogxS31gPPQnQBdprrnSe
4
+ g99DGQ3PP3ut2eqRyKqWFtt6Cc3x7UfLXuwvdjgEHE+v6+XboDI7AgMBAAE=
5
+ -----END RSA PUBLIC KEY-----
@@ -0,0 +1,12 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module Dito
4
+ class Configuration
5
+ attr_accessor :api_key, :secret
6
+ attr_writer :environment
7
+
8
+ def environment
9
+ @environment || 'production'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module Dito
4
+ def self.domains module_name
5
+ domains = {
6
+ :js => 'js',
7
+ :analytics => 'analytics',
8
+ :login => 'login',
9
+ :events => 'events',
10
+ :share => 'share',
11
+ :comments => 'comments',
12
+ :ranking => 'ranking',
13
+ :badge => 'badge',
14
+ :notification => 'notification'
15
+ }
16
+
17
+ if domains[module_name.to_sym].present?
18
+ name = domains[module_name.to_sym]
19
+
20
+ url = case @configuration.environment
21
+ when "production"
22
+ "https://#{name}.plataformasocial.com.br"
23
+ when "development"
24
+ "http://#{name}.dev.plataformasocial.com.br"
25
+ when "test"
26
+ "http://#{name}.dev.plataformasocial.com.br"
27
+ when "staging"
28
+ "http://#{name}.dev.plataformasocial.com.br"
29
+ end
30
+
31
+ url
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,48 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module Dito
4
+ def self.identify user = {}
5
+ Dito.symbolize_keys!(user)
6
+
7
+ params = {}
8
+
9
+ if user[:facebook_id].present?
10
+ network_name = 'facebook'
11
+ id = user[:facebook_id]
12
+ params[:network_name] = 'fb'
13
+ elsif user[:google_plus_id].present?
14
+ network_name = 'plus'
15
+ id = user[:google_plus_id]
16
+ params[:network_name] = 'pl'
17
+ elsif user[:twitter_id].present?
18
+ network_name = 'twitter'
19
+ id = user[:twitter_id]
20
+ params[:network_name] = 'tw'
21
+ elsif user[:id].present?
22
+ network_name = 'portal'
23
+ id = user[:id]
24
+ params[:network_name] = 'pt'
25
+ else
26
+ return { error: { message: 'Missing the user id param. See the available options here: http://developers.dito.com.br/docs/sdks/ruby' } }
27
+ end
28
+
29
+ params[:user_data] = {}
30
+
31
+ if network_name == 'portal'
32
+ params[:user_data].merge!(user)
33
+ params[:user_data].delete(:id)
34
+ else
35
+ params[:user_data][:data] = user[:data]
36
+ end
37
+
38
+ if params[:user_data][:data].present? && params[:user_data][:data].is_a?(Hash)
39
+ params[:user_data][:data] = params[:user_data][:data].to_json
40
+ end
41
+
42
+ params[:access_token] = user[:access_token] if user[:access_token].present?
43
+ params[:signed_request] = user[:signed_request] if user[:signed_request].present?
44
+ params[:id_token] = user[:id_token] if user[:id_token].present?
45
+
46
+ Dito::Request.post 'login', "/users/#{network_name}/#{id}/signup", params
47
+ end
48
+ end
@@ -0,0 +1,46 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'rsa'
4
+ require 'openssl'
5
+ require 'faraday'
6
+ require 'faraday_middleware'
7
+
8
+ module Dito
9
+ class Request
10
+
11
+ def self.post module_name, path, params = {}, headers = {}
12
+ make_request module_name, path, params, headers, 'post'
13
+ end
14
+
15
+ def self.get module_name, path, params = {}, headers = {}
16
+ make_request module_name, path, params, headers, 'get'
17
+ end
18
+
19
+ def self.put module_name, path, params = {}, headers = {}
20
+ make_request module_name, path, params, headers, 'put'
21
+ end
22
+
23
+ def self.delete module_name, path, params = {}, headers = {}
24
+ make_request module_name, path, params, headers, 'delete'
25
+ end
26
+
27
+ def self.make_request module_name, path, params = {}, headers = {}, method = "get"
28
+ conn = Faraday.new(:url => Dito.domains(module_name)) do |faraday|
29
+ faraday.request :url_encoded # form-encode POST params
30
+ faraday.response :json, :content_type => 'application/json'
31
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
32
+ end
33
+
34
+ signature = OpenSSL::PKey::RSA.new(File.read("#{Dito.root}/dito.pem")).public_encrypt Dito.secret
35
+
36
+ params = {
37
+ :network_name => "fb",
38
+ :platform_api_key => Dito.api_key,
39
+ :signature => signature
40
+ }.merge(params)
41
+
42
+ response = conn.send method, path, params, headers
43
+ response.body
44
+ end
45
+ end
46
+ end
data/lib/dito/track.rb ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module Dito
4
+ def self.track options = {}
5
+ Dito.symbolize_keys!(options)
6
+
7
+ if options[:reference].present?
8
+ id = options[:reference]
9
+ id_type = nil
10
+ elsif options[:facebook_id].present?
11
+ id = options[:facebook_id]
12
+ id_type = 'facebook_id'
13
+ elsif options[:google_plus_id].present?
14
+ id = options[:google_plus_id]
15
+ id_type = 'google_plus_id'
16
+ elsif options[:twitter_id].present?
17
+ id = options[:twitter_id]
18
+ id_type = 'twitter_id'
19
+ elsif options[:id].present?
20
+ id = options[:id]
21
+ id_type = 'id'
22
+ else
23
+ return { error: { message: 'Missing the user id param. See the available options here: http://developers.dito.com.br/docs/sdks/ruby' } }
24
+ end
25
+
26
+ params = { event: options[:event].to_json }
27
+ params[:id_type] = id_type if id_type.present?
28
+
29
+ Dito::Request.post 'events', "/users/#{id}/", params
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module Dito
4
+ VERSION = "0.0.1"
5
+ end
data/lib/dito.rb ADDED
@@ -0,0 +1,38 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require "helpers/symbolize_keys"
4
+
5
+ require "dito/version"
6
+ require "dito/configuration"
7
+ require "dito/domains"
8
+ require "dito/request"
9
+ require "dito/identify"
10
+ require "dito/track"
11
+
12
+ module Dito
13
+ def self.root
14
+ File.expand_path '../..', __FILE__
15
+ end
16
+
17
+ class << self
18
+ def configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+
22
+ def configure
23
+ yield(configuration)
24
+ end
25
+
26
+ def api_key
27
+ configuration.api_key
28
+ end
29
+
30
+ def secret
31
+ configuration.secret
32
+ end
33
+
34
+ def environment
35
+ configuration.environment
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'active_support/core_ext/hash'
4
+
5
+ module Dito
6
+ def self.symbolize_keys!(thing)
7
+ case thing
8
+ when Array
9
+ thing.each{|v| symbolize_keys!(v)}
10
+ when Hash
11
+ thing.symbolize_keys!
12
+ thing.values.each{|v| symbolize_keys!(v)}
13
+ end
14
+ thing
15
+ end
16
+
17
+ def self.symbolize_keys(thing)
18
+ case thing
19
+ when Array
20
+ thing.map{|v| symbolize_keys(v)}
21
+ when Hash
22
+ inj = thing.inject({}) {|h, (k,v)| h[k] = symbolize_keys(v); h}
23
+ inj.symbolize_keys
24
+ else
25
+ thing
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dito
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcos Nogueira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday_middleware
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Essa gem tem como objetivo automatizar a integração com a Rest API da
70
+ Dito.
71
+ email:
72
+ - marcos.nogueira@dito.com.br
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - dito.gemspec
83
+ - dito.pem
84
+ - lib/dito.rb
85
+ - lib/dito/configuration.rb
86
+ - lib/dito/domains.rb
87
+ - lib/dito/identify.rb
88
+ - lib/dito/request.rb
89
+ - lib/dito/track.rb
90
+ - lib/dito/version.rb
91
+ - lib/helpers/symbolize_keys.rb
92
+ homepage: http://dito.com.br/
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Gem para integração com a plataforma da Dito
116
+ test_files: []