edh 0.2 → 0.3

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.
@@ -1,3 +1,9 @@
1
+ v0.3
2
+ ====
3
+
4
+ * Allow config to be set via a block.
5
+
6
+
1
7
  v0.2
2
8
  ====
3
9
 
@@ -3,18 +3,39 @@ require 'edh/api/rest_api'
3
3
 
4
4
  module EDH
5
5
  module Passport
6
+ class << self
7
+ attr_accessor :configuration
8
+
9
+ def config
10
+ self.configuration || Configuration.new
11
+ end
12
+ end
13
+
14
+ def self.configure
15
+ self.configuration ||= Configuration.new
16
+ yield(configuration)
17
+ end
18
+
19
+ class Configuration
20
+ attr_accessor :access_token, :app_access_token, :server
21
+
22
+ def initialize
23
+ end
24
+ end
25
+
6
26
  class API
27
+ attr_accessor :access_token, :app_access_token, :server
28
+
7
29
  # Creates a new API client.
8
30
  # @param [String] access_token access token
9
31
  # @note If no access token is provided, you can only access some public information.
10
32
  # @return [EDH::Passport::API] the API client
11
33
  def initialize options = {}
12
- @access_token = options[:access_token]
13
- @app_access_token = options[:app_token]
14
- @server = options[:server]
34
+ @access_token = options[:access_token] || Passport.config.access_token
35
+ @app_access_token = options[:app_access_token] || Passport.config.app_access_token
36
+ @server = options[:server] || Passport.config.server
15
37
  end
16
38
 
17
- attr_accessor :access_token
18
39
 
19
40
  include RestAPIMethods
20
41
 
@@ -1,3 +1,3 @@
1
1
  module EDH
2
- VERSION = "0.2"
2
+ VERSION = "0.3"
3
3
  end
data/readme.md CHANGED
@@ -1,36 +1,53 @@
1
+ [![Build Status](https://travis-ci.org/everydayhero/edh.png?branch=master)](https://travis-ci.org/everydayhero/edh)
2
+
1
3
  ####config/initializers
2
- #### defaults to using production
4
+
5
+ ####optional
3
6
  ```ruby
4
- $passport_client = EDH::Passport::API.new
7
+ #Configure passport connection
8
+ EDH::Passport.configure do |config|
9
+ config.server = 'http://dummy-passport.dev'
10
+ config.app_access_token = "123456"
11
+ end
5
12
  ```
6
13
 
7
- ####optional
14
+ ##Setup a client without a user access token
8
15
  ```ruby
9
- #options: app_token, server, access_token (user)
10
- #access_token is used for sending requests first, then falls back to app_token if that exists.
11
- $passport_client = EDH::Passport::API.new(:server => "http://dummy-passport.dev")
16
+ passport_client = EDH::Passport::API.new
12
17
  ```
13
- ####set the user token
18
+
19
+ ##Setup a client with a user access token
14
20
  ```ruby
15
- $passport_client.access_token = "abc"
21
+ passport_client = EDH::Passport::API.new(:access_token => "user_token")
16
22
  ```
17
23
 
18
24
  ####create returns an action id
19
25
  ```ruby
20
- $passport_client.create("pages.fundraise", {:abc => "def", :cats => "dogs"})
26
+ passport_client.create("pages.fundraise", {:abc => "def", :cats => "dogs"})
21
27
  => 1234
22
28
  #sending json example
23
- $passport_client.create("pages.fundraise", "{\"abc\":\"def\",\"cats\":\"dogs\"}")
29
+ passport_client.create("pages.fundraise", "{\"abc\":\"def\",\"cats\":\"dogs\"}")
24
30
  ```
25
31
 
26
32
  ####update an action
27
33
  ```ruby
28
- $passport_client.update(1234, {:abc => "12345", :cats => "6789"})
34
+ passport_client.update(1234, {:abc => "12345", :cats => "6789"})
29
35
  ```
30
36
 
31
37
  ####delete an action
32
38
  ```ruby
33
- $passport_client.delete(1234)
39
+ passport_client.delete(1234)
40
+ ```
41
+
42
+ Errors
43
+ -----
44
+
45
+ Errors that can be raised are:
46
+ ```ruby
47
+ EDH::Passport::ServerError #5XX error on Passport
48
+ EDH::Passport::ClientError #4XX error on Passport
49
+ MultiJson::DecodeError #Response decode error
50
+ Faraday::Error::ConnectionFailed #connection failure
34
51
  ```
35
52
 
36
53
 
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "EDH::Passport::API" do
4
4
  before(:each) do
5
+ EDH::Passport.configuration = nil
5
6
  @service = EDH::Passport::API.new
6
7
  end
7
8
 
@@ -35,6 +36,24 @@ describe "EDH::Passport::API" do
35
36
  service = EDH::Passport::API.new(:access_token => token)
36
37
  service.access_token.should == token
37
38
  end
39
+
40
+ it "has an attr_reader for app token" do
41
+ EDH::Passport.configure do |config|
42
+ config.app_access_token = "my app token"
43
+ end
44
+
45
+ service = EDH::Passport::API.new
46
+ service.app_access_token.should == "my app token"
47
+ end
48
+
49
+ it "has an attr_reader for server" do
50
+ EDH::Passport.configure do |config|
51
+ config.server = "http://example.com"
52
+ end
53
+
54
+ service = EDH::Passport::API.new
55
+ service.server.should == "http://example.com"
56
+ end
38
57
 
39
58
  it "gets the attribute of a EDH::HTTPService::Response given by the http_component parameter" do
40
59
  http_component = :method_name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edh
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: