giocopro 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/init.rb ADDED
@@ -0,0 +1,11 @@
1
+ begin
2
+ require File.join(File.dirname(__FILE__), 'lib', 'giocopro')
3
+ rescue LoadError
4
+ begin
5
+ require 'giocopro'
6
+ rescue LoadError => e
7
+ raise e unless defined?(Rake) &&
8
+ (Rake.application.top_level_tasks.include?('gems') ||
9
+ Rake.application.top_level_tasks.include?('gems:install'))
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ module GeneratorInstructions
3
+ def instructions
4
+ puts <<-EOS
5
+
6
+ =======================================================
7
+
8
+ Gioco Pro successfully installed.
9
+
10
+ 1. You need to setup an environment variable (GIOCO_PRO_TOKEN) for your Application Token.
11
+ 2. You will find your token on http://app.gioco.pro/ on Manage > Application Token
12
+
13
+ For usage and more infomation go to the documentation:
14
+ https://github.com/giocoapp/giocopro
15
+
16
+ =======================================================
17
+
18
+ EOS
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ module ModelGenerator
2
+ def adding_methods
3
+ inject_into_class "app/models/#{@model_name}.rb", @model_name.capitalize, "include GiocoResource\n"
4
+ copy_file find_in_source_paths("config.rb"), "config/initializers/giocopro.rb"
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ require 'rails/generators/base'
2
+ require 'generators/gioco_pro/model_generator'
3
+ require 'generators/gioco_pro/generator_instructions'
4
+
5
+ module GiocoPro
6
+ class SetupGenerator < Rails::Generators::Base
7
+ include ModelGenerator
8
+ include GeneratorInstructions
9
+
10
+ source_root File.expand_path("../../templates", __FILE__)
11
+
12
+ desc "Setup Gioco for a unique resource"
13
+
14
+ def execute
15
+ @model_name = ask("What is your resource model name? (eg. user)")
16
+ adding_methods
17
+ instructions
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1 @@
1
+ require 'giocopro/gioco_resource'
@@ -0,0 +1,13 @@
1
+ module GiocoResource
2
+ def gioco_data
3
+ gioco_object.get_resource(self.id)
4
+ end
5
+
6
+ def track_event(name)
7
+ gioco_object.track_event(name, self.id)
8
+ end
9
+
10
+ def gioco_object
11
+ GiocoPro::GiocoPro.new
12
+ end
13
+ end
data/lib/giocopro.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'json'
2
+ require 'net/http'
3
+
4
+ module GiocoPro
5
+ class GiocoPro
6
+ def initialize(token=false)
7
+ @http = Net::HTTP.new('app.gioco.pro')
8
+ @headers = {'Content-Type' =>'application/json', 'Token' =>(token) ? token : ENV['GIOCO_PRO_TOKEN']}
9
+ end
10
+
11
+ def get_resource(aid)
12
+ get_data('get_resource.json', aid)
13
+ end
14
+
15
+ def track_event(name, aid)
16
+ data = {'event' => {'name' => name}}
17
+ post_data('track_event.json', aid, data)
18
+ end
19
+
20
+ private
21
+
22
+ def resource_data(data, aid)
23
+ data ||= {}
24
+ data['resource'] = {'aid' => aid}
25
+ data
26
+ end
27
+
28
+ def get_data(url, aid)
29
+ req = Net::HTTP::Get.new(('/api/' + url), @headers)
30
+ request!(nil, aid, req)
31
+ end
32
+
33
+ def post_data(url, aid, data)
34
+ req = Net::HTTP::Post.new(('/api/' + url), @headers)
35
+ request!(data, aid, req)
36
+ end
37
+
38
+ def request!(data, aid, req)
39
+ req.body = resource_data(data, aid).to_json
40
+ res = @http.request(req)
41
+ JSON.parse(res.body)
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: giocopro
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Gioco Pro
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2014-08-26 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Gioco Pro gem is the SDK of Gioco Pro service a easy way to implement gamification based on plug and play concept. Doesn't matter if you already have a full and functional database, Gioco will smoothly integrate everything and provide all methods and analytics that you might need.
23
+ email: joaomdmoura@gioco.pro
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/giocopro.rb
32
+ - lib/generators/gioco_pro/generator_instructions.rb
33
+ - lib/generators/gioco_pro/model_generator.rb
34
+ - lib/generators/gioco_pro/setup_generator.rb
35
+ - lib/generators/templates/config.rb
36
+ - lib/giocopro/gioco_resource.rb
37
+ - init.rb
38
+ has_rdoc: true
39
+ homepage: http://gioco.pro/
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.6.2
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: The Gioco Pro gem for Ruby on Rails applications.
72
+ test_files: []
73
+