apontador_oauth2 0.1.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd3614f0fdccf469b80aa8a03a9e1d8957232e58
4
+ data.tar.gz: 22cb17410a5e1429ad5cccc488f65e10099ce800
5
+ SHA512:
6
+ metadata.gz: a75bb4ad0933864ae3b5e6643221b47a8c3edd1b009e747a171a8a10018476821505219843d823c8fa3857f3dd57c30f1412ee12e3a29381368fa0c4fcd82261
7
+ data.tar.gz: 9b67d2236e5e3bb508075f58acc216d36fd6956cb7fb83b4c04fd292c546be391b09a4457c871b53825a05bec095ecd08a2e10250ecae70e90e0623d715d77ff
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ tmp/*
3
+ coverage
4
+ coverage/*
5
+ Guardfile
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ # uncomment this line if your project needs to run something other than `rake`:
7
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+ gem "faraday"
3
+ gem "json", "~> 1.8.0"
4
+ group :test do
5
+ gem "rspec"
6
+ gem "guard-rspec"
7
+ gem "fakeweb"
8
+ gem "webmock"
9
+ gem 'simplecov', :require => false
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ coderay (1.0.9)
6
+ crack (0.4.1)
7
+ safe_yaml (~> 0.9.0)
8
+ diff-lcs (1.2.4)
9
+ fakeweb (1.3.0)
10
+ faraday (0.8.8)
11
+ multipart-post (~> 1.2.0)
12
+ ffi (1.9.0)
13
+ formatador (0.2.4)
14
+ guard (1.8.3)
15
+ formatador (>= 0.2.4)
16
+ listen (~> 1.3)
17
+ lumberjack (>= 1.0.2)
18
+ pry (>= 0.9.10)
19
+ thor (>= 0.14.6)
20
+ guard-rspec (3.0.3)
21
+ guard (>= 1.8)
22
+ rspec (~> 2.13)
23
+ json (1.8.0)
24
+ listen (1.3.1)
25
+ rb-fsevent (>= 0.9.3)
26
+ rb-inotify (>= 0.9)
27
+ rb-kqueue (>= 0.2)
28
+ lumberjack (1.0.4)
29
+ method_source (0.8.2)
30
+ multi_json (1.8.0)
31
+ multipart-post (1.2.0)
32
+ pry (0.9.12.2)
33
+ coderay (~> 1.0.5)
34
+ method_source (~> 0.8)
35
+ slop (~> 3.4)
36
+ rb-fsevent (0.9.3)
37
+ rb-inotify (0.9.2)
38
+ ffi (>= 0.5.0)
39
+ rb-kqueue (0.2.0)
40
+ ffi (>= 0.5.0)
41
+ rspec (2.14.1)
42
+ rspec-core (~> 2.14.0)
43
+ rspec-expectations (~> 2.14.0)
44
+ rspec-mocks (~> 2.14.0)
45
+ rspec-core (2.14.5)
46
+ rspec-expectations (2.14.2)
47
+ diff-lcs (>= 1.1.3, < 2.0)
48
+ rspec-mocks (2.14.3)
49
+ safe_yaml (0.9.7)
50
+ simplecov (0.7.1)
51
+ multi_json (~> 1.0)
52
+ simplecov-html (~> 0.7.1)
53
+ simplecov-html (0.7.1)
54
+ slop (3.4.6)
55
+ thor (0.18.1)
56
+ webmock (1.13.0)
57
+ addressable (>= 2.2.7)
58
+ crack (>= 0.3.2)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ fakeweb
65
+ faraday
66
+ guard-rspec
67
+ json (~> 1.8.0)
68
+ rspec
69
+ simplecov
70
+ webmock
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 edereduardo
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,30 @@
1
+ [![Build Status](https://travis-ci.org/eder/apontador_oauth2.png?branch=master)](https://travis-ci.org/eder/apontador_oauth2)
2
+ # ApontadorOauth2
3
+
4
+ TODO: Write a gem description
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'apontador_oauth2'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install apontador_oauth2
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'apontador_oauth2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "apontador_oauth2"
8
+ spec.version = ApontadorOauth2::VERSION
9
+ spec.authors = ["edereduardo"]
10
+ spec.email = ["eder.esilva@gmail.com"]
11
+ spec.description = %q{Apontador Oauth2 is a helper for help requests to Api of Apontador}
12
+ spec.summary = %q{A tool for authenticator with Oauth2 of Apontador}
13
+ spec.homepage = "http://edereduardo.wordpress.com/"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+ spec.add_runtime_dependency "faraday", "~> 0.8.8"
20
+ spec.add_runtime_dependency "json", "~> 1.8.0"
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ end
@@ -0,0 +1,4 @@
1
+ require "apontador_oauth2/version"
2
+ require "apontador_oauth2/user"
3
+ require "apontador_oauth2/client"
4
+ require "apontador_oauth2/request"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'net/http'
3
+ require 'net/https'
4
+ require 'faraday'
5
+ require 'json'
6
+ module ApontadorOauth2
7
+ class Client
8
+ attr_accessor :token, :options
9
+ def initialize(options)
10
+ @options = {
11
+ :grant_type => "client_credentials",
12
+ :username => "",
13
+ :password => "",
14
+ }.merge!(options)
15
+ request
16
+ end
17
+
18
+ def request
19
+ url = URI.parse(@options[:url])
20
+ connection = Faraday.new(:url => url)
21
+ response = connection.post 'oauth/token', @options
22
+ @token = JSON.parse(response.body)['access_token']
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module ApontadorOauth2
2
+ class Request
3
+ def self.send(options)
4
+ conn = Faraday.new(:url => options[:url])
5
+ res = conn.get do |req|
6
+ req.url(options[:path])
7
+ req.headers['Content-Type'] = "application/json"
8
+ req.headers['Authorization'] = "Bearer #{options[:token]}"
9
+ req.headers['Accept'] = "application/json"
10
+ req.body = {:user => options[:user]}.to_json if options[:user]
11
+ end
12
+ res
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ module ApontadorOauth2
2
+ attr_accessor :options
3
+ class User
4
+ def initialize(options={})
5
+ @options = options.merge!({:url => "https://api.apontador.com.br/v2/"})
6
+ end
7
+
8
+ def user_information
9
+ response = request({:path => "users/me"}.merge!(@options))
10
+ json(response.body)
11
+ end
12
+
13
+ def register_user_in_apontador(options)
14
+ res = request( {:path => "users", :user => options}.merge(@options))
15
+ JSON.parse(res.body) unless res.status == 201
16
+ end
17
+
18
+ def request(options)
19
+ Request.send(options)
20
+ end
21
+ private
22
+ def json(data)
23
+ JSON.parse(data)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module ApontadorOauth2
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ describe "With Client id and Client Srecret valids" do
3
+ context "Token" do
4
+ before do
5
+ fake_token_without_authentication
6
+ end
7
+
8
+ it "should return one token valid" do
9
+ logged_with_credentials.token.should be === "token-12345678910"
10
+ end
11
+ end
12
+
13
+ context "Token with email and password valids" do
14
+ before do
15
+ fake_token_with_authentication
16
+ user_logged
17
+ end
18
+ it "should return one token valid" do
19
+ user_logged.token.should be === "token-authenticate-12345678910"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ { "user" : { "address" : { "city" : "Sao Paulo",
2
+ "number" : "0",
3
+ "state" : " SP",
4
+ "street" : "CENTRO DA CIDADE"
5
+ },
6
+ "email" : "jhondoe",
7
+ "id" : "12345",
8
+ "link" : { "rel" : "self",
9
+ "uri" : "https://api.apontador.com.br/v2/users/12345"
10
+ },
11
+ "name" : "Jhon Doe",
12
+ "photos" : { "large" : "https://graph.facebook.com/12345/picture?type=large",
13
+ "medium" : "https://graph.facebook.com/12345/picture?type=normal",
14
+ "original" : "https://graph.facebook.com/12345/picture?type=large",
15
+ "small" : "https://graph.facebook.com/12345/picture?type=square"
16
+ },
17
+ "profile" : { "facebookUrl" : "Jhon Doe",
18
+ "newsletter" : true,
19
+ "relationship" : 1,
20
+ "showPhone" : false,
21
+ "twitterUrl" : "jhondoe"
22
+ },
23
+ "statistics" : { "checkins" : 42,
24
+ "photos" : 4,
25
+ "places" : 2,
26
+ "reviews" : 15
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,26 @@
1
+ module FakeData
2
+ def fake_token_without_authentication
3
+ stub_request(:post, "https://api.apontador.com.br/v2/oauth/token").with(:body => {"client_secret"=>"54321", "username"=>"", "grant_type"=>"client_credentials", "password"=>"", "client_id"=>"12345", "url"=>"https://api.apontador.com.br/v2/"},
4
+ :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.8.8'}).to_return(:status => 200, :body => '{"access_token":"token-12345678910","token_type":"bearer","scope":"read trust write"}', :headers => {})
5
+
6
+
7
+
8
+
9
+
10
+ end
11
+
12
+ def fake_token_with_authentication
13
+ stub_request(:post, "https://api.apontador.com.br/v2/oauth/token").with(:body => {"client_secret"=>"54321", "username"=>"jhondoe@example.com", "grant_type"=>"password", "password"=>"123456", "client_id"=>"12345", "url"=>"https://api.apontador.com.br/v2/"},
14
+ :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.8.8'}).to_return(:status => 200, :body => '{"access_token":"token-authenticate-12345678910","token_type":"bearer","scope":"read trust write"}', :headers => {})
15
+
16
+ end
17
+
18
+ def fake_info_user
19
+ stub_request(:get, "https://api.apontador.com.br/v2/users/me").with(:headers => {'Accept'=>'application/json', 'Authorization'=>'Bearer token-authenticate-12345678910', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.8.8'}).to_return(:status => 200, :body => File.read("spec/fixtures/factories/user.json"), :headers => {})
20
+ end
21
+
22
+ def fake_register_user
23
+ stub_request(:get, "https://api.apontador.com.br/v2/users").with(:body => "{\"user\":{\"name\":\"jhon Doe\",\"email\":\"jhondoe@example.com\",\"password\":\"jhondoe12345\"}}",
24
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'Bearer token-12345678910', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.8.8'}).to_return(:status => 201, :body => "", :headers => {})
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ module Login
2
+ def user_logged
3
+ credentials = { :client_id => "12345",
4
+ :client_secret => "54321",
5
+ :url => "https://api.apontador.com.br/v2/",
6
+ :username => "jhondoe@example.com",
7
+ :password => "123456",
8
+ :grant_type => "password",
9
+ }
10
+ ApontadorOauth2::Client.new(credentials)
11
+ end
12
+
13
+ def logged_with_credentials
14
+ credentials = {:client_id => "12345",
15
+ :client_secret => "54321",
16
+ :url => "https://api.apontador.com.br/v2/"
17
+ }
18
+ ApontadorOauth2::Client.new(credentials)
19
+ end
20
+
21
+ end
File without changes
@@ -0,0 +1,9 @@
1
+ #require "spec_helper"
2
+ #describe "Open request HTTP" do
3
+ #it"Make request" do
4
+ #request = ApontadorOauth2::Request.send({:url => "https://api.apontador.com.br/v2/",
5
+ #:path => "/v2/users/me",
6
+ #:token => "token-12345678910"})
7
+ #request['user'].should_not be_nil
8
+ #end
9
+ #end
@@ -0,0 +1,13 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+ require 'webmock/rspec'
4
+ require 'helpers/fake_data'
5
+ require 'helpers/login'
6
+ require 'rubygems'
7
+ require 'bundler/setup'
8
+ require 'apontador_oauth2' # and any other gems you need
9
+ RSpec.configure do |config|
10
+ config.include FakeData
11
+ config.include Login
12
+ end
13
+
data/spec/user_spec.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+ describe "Interation with data of user" do
3
+ context "User information" do
4
+ before do
5
+ fake_token_with_authentication
6
+ user_logged
7
+ end
8
+ it "Grab User " do
9
+ fake_info_user
10
+ user = ApontadorOauth2::User.new({:token => user_logged.token})
11
+ user.user_information['user'].should_not be_nil
12
+ end
13
+ end
14
+ context "Register user" do
15
+ before do
16
+ fake_token_without_authentication
17
+ fake_register_user
18
+ end
19
+ it "create new user" do
20
+ conf = {:name => "jhon Doe",
21
+ :email => "jhondoe@example.com",
22
+ :password => "jhondoe12345"
23
+ }
24
+
25
+ new_user = ApontadorOauth2::User.new({:token => logged_with_credentials.token})
26
+ new_user.register_user_in_apontador(conf).should be_nil
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apontador_oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - edereduardo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-02 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.8.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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
+ description: Apontador Oauth2 is a helper for help requests to Api of Apontador
70
+ email:
71
+ - eder.esilva@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .travis.yml
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - Guardfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - apontador_oauth2.gemspec
86
+ - lib/apontador_oauth2.rb
87
+ - lib/apontador_oauth2/client.rb
88
+ - lib/apontador_oauth2/request.rb
89
+ - lib/apontador_oauth2/user.rb
90
+ - lib/apontador_oauth2/version.rb
91
+ - spec/client_spec.rb
92
+ - spec/fixtures/factories/user.json
93
+ - spec/helpers/fake_data.rb
94
+ - spec/helpers/login.rb
95
+ - spec/helpers/user_spec.rb
96
+ - spec/request_spec.rb
97
+ - spec/spec_helper.rb
98
+ - spec/user_spec.rb
99
+ homepage: http://edereduardo.wordpress.com/
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.1.3
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: A tool for authenticator with Oauth2 of Apontador
123
+ test_files:
124
+ - spec/client_spec.rb
125
+ - spec/fixtures/factories/user.json
126
+ - spec/helpers/fake_data.rb
127
+ - spec/helpers/login.rb
128
+ - spec/helpers/user_spec.rb
129
+ - spec/request_spec.rb
130
+ - spec/spec_helper.rb
131
+ - spec/user_spec.rb