fitgem_oauth2 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: 4668e05ec00b938a76c13ca40aa46fe6f685b113
4
+ data.tar.gz: 90910ad066bb5eef0d6eb89b082a48da66c14164
5
+ SHA512:
6
+ metadata.gz: 788da8e8b805f8fb654d0c08695c4159cda613256724b183af15388e43cb63c72fcd3d51db9a4e32d42c7f6c4e00f87ea5294b215b6065b01a06d16a03b940b3
7
+ data.tar.gz: e331d68cb25eef55e7b8c3ab7f66e2eb0616948a48052f98b6d9a97447025e2e1fffa56dcf3dd53e46b298973af2f743580b8981e30a825cfdcae26ff1a334b2
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'fitgem_oauth2'
3
+ s.version = '0.0.1'
4
+ s.date = '2016-01-18'
5
+ s.summary = "This gem allows requesting data from Fitbit API using OAuth2"
6
+ s.description = "This gem allows requesting data from Fitbit API using OAuth2"
7
+ s.authors = ["Ankit Gupta"]
8
+ s.email = 'ankit.gupta2801@gmail.com'
9
+ s.files = %w(fitgem_oauth2.gemspec) + `git ls-files -z`.split("\x0").select { |f| f.start_with?("lib/") }
10
+ s.homepage = 'http://rubygems.org/gems/fitgem_oauth2'
11
+ s.license = 'MIT'
12
+
13
+ s.add_runtime_dependency 'faraday', '~> 0.9'
14
+ end
@@ -0,0 +1,5 @@
1
+ require 'fitgem_oauth2/client.rb'
2
+
3
+ module FitgemOauth2
4
+
5
+ end
@@ -0,0 +1,70 @@
1
+ require 'base64'
2
+ require 'faraday'
3
+
4
+ module FitgemOauth2
5
+ class Client
6
+
7
+ attr_accessor :token
8
+
9
+ attr_accessor :user_id
10
+
11
+ def initialize(opts)
12
+ @client_id = opts[:client_id]
13
+ if @client_id.nil?
14
+ puts "TODO. Raise an exception due to missing client id"
15
+ end
16
+
17
+ @client_secret = opts[:client_secret]
18
+ if @client_secret.nil?
19
+ puts "TODO. Raise an exception due to missing client secret"
20
+ end
21
+
22
+ @token = opts[:token]
23
+ if @token.nil?
24
+ puts "TODO. Raise an exception due to missing token"
25
+ end
26
+
27
+ @user_id = opts[:user_id]
28
+ if @user_id.nil?
29
+ puts "TODO. Raise an exception due to missing fitbit user id"
30
+ end
31
+
32
+ @connection = Faraday.new("https://api.fitbit.com")
33
+ end
34
+
35
+
36
+ def activities_on_date(date)
37
+ connection.get "1/user/#{user_id}/activities/date/#{format_date(date)}.json" do |request|
38
+ request.headers['Authorization'] = "Bearer #{token}"
39
+ request.headers['Content-Type'] = "application/x-www-form-urlencoded"
40
+ end
41
+ end
42
+
43
+ def refresh_access_token(refresh_token)
44
+ response = connection.post('/oauth2/token') do |request|
45
+ encoded = Base64.strict_encode64("#{@client_id}:#{@client_secret}")
46
+ request.headers['Authorization'] = "Basic #{encoded}"
47
+ request.headers['Content-Type'] = "application/x-www-form-urlencoded"
48
+ request.params['grant_type'] = "refresh_token"
49
+ request.params['refresh_token'] = refresh_token
50
+ end
51
+ response.body
52
+ end
53
+
54
+ private
55
+
56
+ attr_accessor :connection
57
+
58
+ def format_date(date)
59
+ date
60
+ end
61
+
62
+ def get(url)
63
+
64
+ end
65
+
66
+ def raw_get(url)
67
+ end
68
+
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fitgem_oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ankit Gupta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ description: This gem allows requesting data from Fitbit API using OAuth2
28
+ email: ankit.gupta2801@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - fitgem_oauth2.gemspec
34
+ - lib/fitgem_oauth2.rb
35
+ - lib/fitgem_oauth2/client.rb
36
+ homepage: http://rubygems.org/gems/fitgem_oauth2
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: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.4.6
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: This gem allows requesting data from Fitbit API using OAuth2
60
+ test_files: []