lotohelp 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b2e9c9ffd81ee4c679ae599879fbf5bd35e6c465
4
+ data.tar.gz: 7f4897b0e7683adb5c901e42ede8d75e2d511927
5
+ SHA512:
6
+ metadata.gz: 12fab328e0b23b157328e2f454df0d7765277b7e352443d3c615e44887a6b1d736f1c22417099ea58353ad72821e14ab36b0a9ed42364374039a04ecdd085915
7
+ data.tar.gz: e56fec2225b947331b81f9f9b8f837110f5b98e5b8d06b9951cfda7035f96c8d21196f8530ce32de338ec55907480813cff1023419ed9b284774311830633117
@@ -0,0 +1,23 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .env
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lotohelp.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Hugo Dias
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.
@@ -0,0 +1,32 @@
1
+ # Lotohelp
2
+
3
+ Ruby Gem para recuperar informações das loterias da caixa econômica federal
4
+
5
+ ## Installation
6
+
7
+ Adicione esta gem no seu gemfile:
8
+
9
+ gem 'lotohelp'
10
+
11
+ E execute:
12
+
13
+ $ bundle
14
+
15
+ Ou instale você mesmo com:
16
+
17
+ $ gem install lotohelp
18
+
19
+ ## Utilizando
20
+
21
+ ### Rails
22
+
23
+ Adicione seu AUTH_TOKEN e AUTH_EMAIL em um arquivo de configurações, ex: `config/initializers/lotohelp.rb`
24
+
25
+ ```
26
+ Lotohelp.configure do |config|
27
+ config.auth_token = "AUTH_TOKEN_AQUI"
28
+ config.auth_email = "AUTH_EMAIL_AQUI"
29
+ end
30
+ ```
31
+
32
+ Para conseguir uma auth_token e auth_email, crie uma conta em (https://www.lotohelper.com)[https://www.lotohelper.com]
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
@@ -0,0 +1,25 @@
1
+ require "lotohelp/version"
2
+ require "lotohelp/configuration"
3
+ require "lotohelp/request"
4
+ require "lotohelp/concourse"
5
+ require "lotohelp/lottery"
6
+ require "typhoeus"
7
+ require "json"
8
+
9
+ module Lotohelp
10
+ @hostname = "www.lotohelper.com/api"
11
+ @protocol = "https"
12
+ @version = "v1"
13
+
14
+ def self.configure
15
+ yield Config
16
+ end
17
+
18
+ def self.request
19
+ yield Request
20
+ end
21
+
22
+ def self.entrypoint
23
+ "#{@protocol}://#{@hostname}/#{@version}"
24
+ end
25
+ end
@@ -0,0 +1,42 @@
1
+ module Lotohelp
2
+
3
+ # Requests library
4
+ #
5
+ module Concourse
6
+ extend self
7
+
8
+ # Get a specific concourse from lottery
9
+ #
10
+ # @example Get the concourse 1010 from megasena
11
+ # Lotohelp::Concourse.get(1010, 'megasena')
12
+ # @return [ Hash ]
13
+ def self.get(concourse_number, lottery_slug)
14
+ self.validate_params(concourse_number, lottery_slug)
15
+
16
+ Request::get("/lotteries/#{lottery_slug}/concourse/#{concourse_number}")
17
+ end
18
+
19
+ # Check for hits on a specific concourse
20
+ #
21
+ # @example Check how many hits for [01,02,03] on concourse 1010 from megasena
22
+ # numbers = ["01","02","03"]
23
+ # Lotohelp::Concourse.check(numbers, 1010, 'megasena')
24
+ # @return [ Hash ]
25
+ def self.check(numbers=nil, concourse_number=nil, lottery_slug=nil)
26
+ self.validate_params(concourse_number, lottery_slug, numbers)
27
+
28
+ Request::post("/check/#{lottery_slug}/#{concourse_number}", {dozens: numbers.join('|'), concourse_number: concourse_number, lottery_slug: lottery_slug})
29
+ end
30
+
31
+ private
32
+
33
+ def self.validate_params(concourse_number=nil, lottery_slug=nil, numbers=nil)
34
+ if !numbers.nil?
35
+ raise ArgumentError.new("Numbers should be an Array, #{numbers.class} given") unless numbers.is_a?(Array)
36
+ end
37
+ raise ArgumentError.new("Concourse number should be an Integer, #{concourse_number.class} given") if concourse_number.nil? || !concourse_number.is_a?(Integer)
38
+ raise ArgumentError.new("Lottery Slug should be an String, #{lottery_slug.class} given") if lottery_slug.nil? || !lottery_slug.is_a?(String)
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ module Lotohelp
2
+
3
+ # Lotohelp configuration used to set global options.
4
+ #
5
+ # @example Set the configuration options within a block.
6
+ # Lotohelp.configure do |config|
7
+ # config.auth_token = "123123"
8
+ # config.auth_email = "example@gmail.com"
9
+ # end
10
+ #
11
+ # @example Set the configuration directly.
12
+ # Lotohelp::Config.auth_token = "123123"
13
+ module Config
14
+ extend self
15
+
16
+ # Defines auth token from user
17
+ #
18
+ # @return [ String ]
19
+ attr_accessor :auth_token
20
+
21
+ # Defines auth email from user
22
+ #
23
+ # @return [ String ]
24
+ attr_accessor :auth_email
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ module Lotohelp
2
+
3
+ # Requests library
4
+ #
5
+ module Lottery
6
+ extend self
7
+
8
+ # Get the last concourse from a specific lottery
9
+ #
10
+ # @example Get the last concourse from Mega Sena
11
+ # Lotohelp::Lottery.last('megasena')
12
+ # => [{name: 'megasema', ...}]
13
+ #
14
+ # @return [ Hash ]
15
+ def self.last(lottery_slug=nil)
16
+ raise ArgumentError("Lottery slug should be an String, #{lottery_slug.class} given") unless lottery_slug.is_a? String
17
+
18
+ Request::get("/lotteries/#{lottery_slug}/last")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,55 @@
1
+ module Lotohelp
2
+
3
+ # Requests library
4
+ #
5
+ module Request
6
+ extend self
7
+
8
+ # Constructing a GET request on the API
9
+ #
10
+ # @return [ Hash ]
11
+ def self.get(path)
12
+ params = {
13
+ user_token: Lotohelp::Config.auth_token,
14
+ user_email: Lotohelp::Config.auth_email
15
+ }
16
+
17
+ self.do_req(path, :get, params)
18
+ end
19
+
20
+ # Constructing a POST request on the API
21
+ #
22
+ # @return [ Hash ]
23
+ def self.post(path, params)
24
+ auth_params = {
25
+ user_token: Lotohelp::Config.auth_token,
26
+ user_email: Lotohelp::Config.auth_email
27
+ }
28
+ request_params = auth_params.merge!(params)
29
+
30
+ self.do_req(path, :post, request_params)
31
+ end
32
+
33
+ private
34
+
35
+ # Executing the request on the API
36
+ #
37
+ # @return [ Hash ]
38
+ def self.do_req(path, method, params)
39
+ request = Typhoeus::Request.new(
40
+ "#{Lotohelp.entrypoint}#{path}",
41
+ method: method,
42
+ params: params,
43
+ headers: { Accept: "application/json" }
44
+ )
45
+
46
+ result = request.run
47
+
48
+ response = {
49
+ :code => result.code,
50
+ :body => JSON.parse(result.body),
51
+ :header => result.headers
52
+ }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module Lotohelp
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lotohelp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lotohelp"
8
+ spec.version = Lotohelp::VERSION
9
+ spec.authors = ["Hugo Dias"]
10
+ spec.email = ["hugo.victor.dias.teodoro@gmail.com"]
11
+ spec.summary = %q{Seu ajudante de loterias}
12
+ spec.description = %q{Esta gem possibilita a extração de diversas informações das loterias da caixa economica federal.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency 'pry'
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'dotenv'
26
+ spec.add_dependency 'typhoeus'
27
+ spec.add_dependency 'json'
28
+ end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+ require 'dotenv'
3
+ require 'pry'
4
+ Dotenv.load
5
+
6
+ describe Lotohelp do
7
+
8
+ before(:all) do
9
+ @lottery_slug = "megasena"
10
+ @concourse_number = 780
11
+ @auth_token = ENV['AUTH_TOKEN']
12
+ @auth_email = ENV['AUTH_EMAIL']
13
+ end
14
+
15
+ describe '#configuration' do
16
+ it 'should return the configuration variable or nil' do
17
+ token = "123123"
18
+
19
+ Helpers::Helper.configure_api(token,nil)
20
+
21
+ expect(Lotohelp::Config.auth_token).to eq token
22
+ expect(Lotohelp::Config.auth_email).to eq nil
23
+ end
24
+ end
25
+
26
+ describe '#request' do
27
+ it 'should return 401 when auth information is empty or invalid' do
28
+ token = nil
29
+ email = "example@gmail.com"
30
+
31
+ Helpers::Helper.configure_api(token, email)
32
+
33
+ response = Lotohelp::Lottery.last(@lottery_slug)
34
+
35
+ expect(response[:code]).to eq 401
36
+ end
37
+ end
38
+
39
+ describe '#requests' do
40
+
41
+ # Configuring API token
42
+ # To set your credentials create an .env file and set the
43
+ # AUTH_TOKEN and AUTH_EMAIL variables
44
+ #
45
+ before(:all) do
46
+ Helpers::Helper.configure_api(@auth_token, @auth_email)
47
+ end
48
+
49
+ describe '#last_concourse' do
50
+ it 'should validate params' do
51
+ expect{ Lotohelp::Lottery.last() }.to raise_error
52
+ end
53
+
54
+ it 'should validate lottery slug' do
55
+ response = Lotohelp::Lottery.last('megamega')
56
+
57
+ expect(response[:body]["code"]).to eq 1
58
+ end
59
+
60
+ it 'should return last concourse' do
61
+ response = Lotohelp::Lottery.last(@lottery_slug)
62
+
63
+ expect(response[:code]).to eq 200
64
+ expect(response[:body][0]["concourse"].class).to eq Hash
65
+ end
66
+ end
67
+
68
+ describe '#get_concourse' do
69
+ it 'should validate params' do
70
+ expect{ Lotohelp::Concourse.get() }.to raise_error(ArgumentError)
71
+ end
72
+
73
+ it 'should return a specific concourse' do
74
+ response = Lotohelp::Concourse.get(@concourse_number, @lottery_slug)
75
+
76
+ expect(response[:code]).to eq 200
77
+ expect(response[:body][0]["concourse"]["name"]).to eq @concourse_number
78
+ end
79
+ end
80
+
81
+ describe '#check' do
82
+ it 'should validate params' do
83
+ expect{ Lotohelp::Concourse.check() }.to raise_error(ArgumentError)
84
+ end
85
+
86
+ it 'should check a game' do
87
+ numbers = ["01","02","03", 10, 20]
88
+
89
+ response = Lotohelp::Concourse.check(numbers, @concourse_number, @lottery_slug)
90
+
91
+ expect(response[:code]).to eq 200
92
+ expect(response[:body][0]["game"]["score"].class).to eq Fixnum
93
+ end
94
+ end
95
+
96
+ end
97
+ end
@@ -0,0 +1,12 @@
1
+ require 'lotohelp'
2
+
3
+ module Helpers
4
+ class Helper
5
+ def self.configure_api(token=nil, email=nil)
6
+ Lotohelp.configure do |config|
7
+ config.auth_token = token
8
+ config.auth_email = email
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lotohelp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hugo Dias
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-16 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: typhoeus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Esta gem possibilita a extração de diversas informações das loterias
112
+ da caixa economica federal.
113
+ email:
114
+ - hugo.victor.dias.teodoro@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - lib/lotohelp.rb
125
+ - lib/lotohelp/concourse.rb
126
+ - lib/lotohelp/configuration.rb
127
+ - lib/lotohelp/lottery.rb
128
+ - lib/lotohelp/request.rb
129
+ - lib/lotohelp/version.rb
130
+ - lotohelp.gemspec
131
+ - spec/lotohelp_spec.rb
132
+ - spec/spec_helper.rb
133
+ - tasks/rspec.rake
134
+ homepage: ''
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.2.2
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Seu ajudante de loterias
158
+ test_files:
159
+ - spec/lotohelp_spec.rb
160
+ - spec/spec_helper.rb