numberstoday 0.0.1a

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: 5a48ce8d7d3cad34067a13004f8d11dc2bda9361
4
+ data.tar.gz: 951e5a9996ec7ae61625d4efda28bd6b4e839ffa
5
+ SHA512:
6
+ metadata.gz: d2378bc2054f074f4681d930276d9efc3184df941f194a908366680340b345689becdc7c21ba4c5c1a0e674fe1be67d5f172f2615396e354791b14de9fb17e92
7
+ data.tar.gz: d12b1948ad3f6941026f69a4ee20ad0786ac83b2bfa26e759a969d495f7f1797ccff2c447226448e5fba951abaa6bc66777c2bf42125e98688810cc19c00185d
@@ -0,0 +1,49 @@
1
+ require 'json'
2
+
3
+ class NumbersToday
4
+
5
+ @API_TOKEN = nil
6
+
7
+ def initialize(params)
8
+ response = NumbersToday::Utils.fetch(
9
+ NumbersToday::Endpoints.obtain_api_token,
10
+ data: {
11
+ 'username' => params[:username],
12
+ 'password' => params[:password]
13
+ }
14
+ )
15
+ @API_TOKEN = JSON.parse(response.body)['token']
16
+ self
17
+ end
18
+
19
+ def verboses
20
+ response = NumbersToday::Utils.fetch(
21
+ NumbersToday::Endpoints.verboses,
22
+ data: nil,
23
+ api_token: @API_TOKEN,
24
+ )
25
+ JSON.parse(response.body.to_s)
26
+ end
27
+
28
+ def locations
29
+ response = NumbersToday::Utils.fetch(
30
+ NumbersToday::Endpoints.locations,
31
+ data: nil,
32
+ api_token: @API_TOKEN,
33
+ )
34
+ JSON.parse(response.body.to_s)
35
+ end
36
+
37
+ def count_buttons
38
+ response = NumbersToday::Utils.fetch(
39
+ NumbersToday::Endpoints.count_buttons,
40
+ data: nil,
41
+ api_token: @API_TOKEN,
42
+ )
43
+ JSON.parse(response.body.to_s)
44
+ end
45
+
46
+ end
47
+
48
+ require 'numberstoday/endpoints'
49
+ require 'numberstoday/utils'
@@ -0,0 +1,42 @@
1
+ require 'numberstoday'
2
+
3
+ class NumbersToday::Endpoints
4
+ URL = "https://numbers.today"
5
+ API_URL = "#{URL}/api/rest"
6
+
7
+ def self.obtain_api_token
8
+ return {
9
+ endpoint: URI("#{API_URL}/obtain_api_token/"),
10
+ method: "post",
11
+ }
12
+ end
13
+
14
+ def self.entries
15
+ return {
16
+ endpoint: URI("#{API_URL}/entries/:id"),
17
+ method: "get",
18
+ }
19
+ end
20
+
21
+ def self.verboses
22
+ return {
23
+ endpoint: URI("#{API_URL}/verboses/"),
24
+ method: "get",
25
+ }
26
+ end
27
+
28
+ def self.locations
29
+ return {
30
+ endpoint: URI("#{API_URL}/locations/"),
31
+ method: "get",
32
+ }
33
+ end
34
+
35
+ def self.count_buttons
36
+ return {
37
+ endpoint: URI("#{API_URL}/count_buttons/"),
38
+ method: URI("get"),
39
+ }
40
+ end
41
+
42
+ end
@@ -0,0 +1,15 @@
1
+ require 'http'
2
+ require 'numberstoday'
3
+
4
+ class NumbersToday::Utils
5
+
6
+ def self.fetch(obj, data: {}, api_token: nil)
7
+ if obj[:method] == "get"
8
+ HTTP.headers(:authorization => "Token #{api_token}").get(obj[:endpoint])
9
+ else
10
+ HTTP.post(obj[:endpoint], :form => data)
11
+ end
12
+ end
13
+
14
+ end
15
+
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: numberstoday
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1a
5
+ platform: ruby
6
+ authors:
7
+ - Rafael Albuquerque
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Wrapper to numbers.today in Ruby
28
+ email: me@rafael.pt
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/numberstoday.rb
34
+ - lib/numberstoday/endpoints.rb
35
+ - lib/numberstoday/utils.rb
36
+ homepage: http://rubygems.org/gems/numberstoday
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">"
52
+ - !ruby/object:Gem::Version
53
+ version: 1.3.1
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.4.5.1
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Wrapper to numbers.today in Ruby
60
+ test_files: []