apontador_oauth2 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2885f9e60e9e6c05f0edf4b9d66f86dadd6ff763
4
- data.tar.gz: 34b1b8503365facf34911f5f562527a4dfdfb461
3
+ metadata.gz: dff03d7cd887579995f59ddd9592d15ae1f67a3e
4
+ data.tar.gz: ac5f5312cf8353946ac4fd14c85c63de4ceb23bc
5
5
  SHA512:
6
- metadata.gz: 02983d908b9988b66e8469d2d7be2277ced1cb9cd6e7980136c5d3a4dd1cda79d57da24c7d668768e7a9cbe20cc0fe18308000d71927e8bd9442a0e37dc1e521
7
- data.tar.gz: 2e383de9cce0c929fe0c49537ea8ea0dc17def5efad604f09c2cd3bfe1e3298e332840c5726e6fb0d6efca0b5d9ce378b030aacfc1207433ca3525bd68676945
6
+ metadata.gz: 67f5d956f24824f3f5e5ad768ba1a01f190eb29a4f94775facb98295ed8304b817beec70238e0cfa1ca6d7a1fdead58eb8087d9e29af21413018a451f9af3fd4
7
+ data.tar.gz: 8ccec0eececfa7c25e6d5542b9be9dbbbfdb7bf08304e542ae5f4ba6ba8d84406c2dd759cfdc848c3c6bd8dc11cc54cf0a56747163e4162d9a426a06e0d25e5f
data/.gitignore CHANGED
@@ -3,3 +3,5 @@ tmp/*
3
3
  coverage
4
4
  coverage/*
5
5
  Guardfile
6
+ *.un~
7
+ *.swp
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  [![Build Status](https://travis-ci.org/eder/apontador_oauth2.png?branch=master)](https://travis-ci.org/eder/apontador_oauth2)
2
+ [![Gem Version](https://badge.fury.io/rb/apontador_oauth2.png)](http://badge.fury.io/rb/apontador_oauth2)
2
3
  # ApontadorOauth2
3
-
4
- TODO: Write a gem description
5
-
4
+ Ruby client for the OAuth 2.0 to site Apontador, still in process of development.
6
5
  ## Installation
7
6
 
8
7
  Add this line to your application's Gemfile:
@@ -17,9 +16,54 @@ Or install it yourself as:
17
16
 
18
17
  $ gem install apontador_oauth2
19
18
 
20
- ## Usage
19
+ ## Usage Examples
20
+
21
+ Get Token with app trust:
22
+ ```ruby
23
+
24
+ credentials = {
25
+ :client_id => "12345", :client_secret => "54321",
26
+ :url => "https://api.apontador.com.br/v2/"
27
+ }
28
+ client = ApontadorOauth2::Client.new(credentials)
29
+
30
+ client.token
31
+ #=> one-number-token-valid
32
+ ```
33
+
34
+ Get token with user authenticated:
35
+ ``` ruby
36
+ credentials = {
37
+ :client_id => "12345", :client_secret => "54321",
38
+ :url => "https://api.apontador.com.br/v2/",
39
+ :username => "jhondoe@example.com",
40
+ :password => "123456",
41
+ :grant_type => "password"
42
+ }
43
+ client = ApontadorOauth2::Client.new(credentials)
44
+ client.token
45
+ #=> one-number-token-valid-authenticate-be-user
46
+ ```
47
+ Register new user with token app of trust:
48
+ ``` ruby
49
+ credentials = {
50
+ :client_id => "12345", :client_secret => "54321",
51
+ :url => "https://api.apontador.com.br/v2/"
52
+ }
53
+ client = ApontadorOauth2::Client.new(credentials)
54
+ new_user = ApontadorOauth2::User.new({:token => client.token})
55
+
56
+ user = {:name => "jhon Doe", :email => "jhondoe@example.com", :password => "jhondoe12345"}
57
+ new_user.register_user_in_apontador(user)
58
+ #=> nil
59
+ ```
60
+
61
+ ##Supported Ruby Versions
21
62
 
22
- TODO: Write usage instructions here
63
+ This library aims to support and is tested against the following Ruby implementations:
64
+ Ruby 1.9.2
65
+ Ruby 1.9.3
66
+ Ruby 2.0.0
23
67
 
24
68
  ## Contributing
25
69
 
@@ -7,18 +7,17 @@ module ApontadorOauth2
7
7
  class Client
8
8
  attr_accessor :token, :options
9
9
  def initialize(options)
10
- @options = {
11
- :grant_type => "client_credentials",
12
- :username => "",
13
- :password => "",
10
+ @options = {:grant_type => "client_credentials",
11
+ :username => "",
12
+ :password => "",
14
13
  }.merge!(options)
15
14
  request
16
15
  end
17
16
 
17
+ private
18
18
  def request
19
- url = URI.parse(@options[:url])
20
- connection = Faraday.new(:url => url)
21
- response = connection.post 'oauth/token', @options
19
+ connection = Faraday.new(:url => URI.parse(@options[:url]))
20
+ response = connection.post '/v2/oauth/token', @options
22
21
  @token = JSON.parse(response.body)['access_token']
23
22
  end
24
23
  end
@@ -11,5 +11,9 @@ module ApontadorOauth2
11
11
  end
12
12
  res
13
13
  end
14
+
15
+ def self.json(data)
16
+ JSON.parse(data)
17
+ end
14
18
  end
15
19
  end
@@ -2,25 +2,21 @@ module ApontadorOauth2
2
2
  attr_accessor :options
3
3
  class User
4
4
  def initialize(options={})
5
- @options = options.merge!({:url => "https://api.apontador.com.br/v2/"})
5
+ @options = options
6
6
  end
7
7
 
8
8
  def user_information
9
- response = request({:path => "users/me"}.merge!(@options))
10
- json(response.body)
9
+ response = request({:path => "/v2/users/me"}.merge!(@options))
10
+ Request.json(response.body)
11
11
  end
12
12
 
13
13
  def register_user_in_apontador(options)
14
14
  res = request( {:path => "users", :user => options}.merge(@options))
15
- JSON.parse(res.body) unless res.status == 201
15
+ Request.json(res.body) if res.status != 201
16
16
  end
17
17
 
18
18
  def request(options)
19
19
  Request.send(options)
20
20
  end
21
- private
22
- def json(data)
23
- JSON.parse(data)
24
- end
25
21
  end
26
22
  end
@@ -1,3 +1,3 @@
1
1
  module ApontadorOauth2
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- describe "With Client id and Client Srecret valids" do
2
+ describe "With Client id and Client Srecret valids" do
3
3
  context "Token" do
4
4
  before do
5
5
  fake_token_without_authentication
@@ -1,16 +1,11 @@
1
1
  module FakeData
2
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/"},
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"},
4
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
5
  end
11
6
 
12
7
  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/"},
8
+ 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"},
14
9
  :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
10
 
16
11
  end
@@ -2,7 +2,7 @@ module Login
2
2
  def user_logged
3
3
  credentials = { :client_id => "12345",
4
4
  :client_secret => "54321",
5
- :url => "https://api.apontador.com.br/v2/",
5
+ :url => "https://api.apontador.com.br",
6
6
  :username => "jhondoe@example.com",
7
7
  :password => "123456",
8
8
  :grant_type => "password",
@@ -11,9 +11,9 @@ module Login
11
11
  end
12
12
 
13
13
  def logged_with_credentials
14
- credentials = {:client_id => "12345",
15
- :client_secret => "54321",
16
- :url => "https://api.apontador.com.br/v2/"
14
+ credentials = { client_id: "12345",
15
+ client_secret: "54321",
16
+ url: "https://api.apontador.com.br"
17
17
  }
18
18
  ApontadorOauth2::Client.new(credentials)
19
19
  end
@@ -7,7 +7,7 @@ describe "Interation with data of user" do
7
7
  end
8
8
  it "Grab User " do
9
9
  fake_info_user
10
- user = ApontadorOauth2::User.new({:token => user_logged.token})
10
+ user = ApontadorOauth2::User.new({token: user_logged.token, url: "https://api.apontador.com.br/v2/" })
11
11
  user.user_information['user'].should_not be_nil
12
12
  end
13
13
  end
@@ -22,7 +22,7 @@ describe "Interation with data of user" do
22
22
  :password => "jhondoe12345"
23
23
  }
24
24
 
25
- new_user = ApontadorOauth2::User.new({:token => logged_with_credentials.token})
25
+ new_user = ApontadorOauth2::User.new({token: logged_with_credentials.token, url: "https://api.apontador.com.br/v2/"})
26
26
  new_user.register_user_in_apontador(conf).should be_nil
27
27
  end
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apontador_oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - edereduardo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-02 00:00:00.000000000 Z
11
+ date: 2014-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  requirements: []
118
118
  rubyforge_project:
119
- rubygems_version: 2.1.3
119
+ rubygems_version: 2.0.3
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: A tool for authenticator with Oauth2 of Apontador