hyperclient 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/lib/hyperclient.rb CHANGED
@@ -35,21 +35,28 @@ module Hyperclient
35
35
  module ClassMethods
36
36
  # Public: Set the entry point of your API.
37
37
  #
38
+ # url - A block to pass the API url.
39
+ #
38
40
  # Returns nothing.
39
- def entry_point(url)
40
- Resource.entry_point = url
41
+ def entry_point(&url)
42
+ Resource.entry_point = url.call
41
43
  end
42
44
 
43
45
  # Public: Sets the authentication options for your API client.
44
46
  #
45
- # type - A String or Symbol with the authentication method. Can be either
46
- # :basic or :digest.
47
- # user - A String with the user.
48
- # password - A String with the password.
47
+ # options - A block used to pass authentication options. Needed data is:
48
+ # type - A String or Symbol with the authentication method. Can be
49
+ # either :basic or :digest.
50
+ # user - A String with the user.
51
+ # password - A String with the password.
52
+ #
53
+ # Example:
54
+ # auth{ {type: :digest, user: 'user', password: 'secret'} }
49
55
  #
50
56
  # Returns nothing.
51
- def auth(type, user, password)
52
- http_options({auth: {type: type, credentials: [user, password]}})
57
+ def auth(&options)
58
+ options = options.call
59
+ http_options({auth: {type: options[:type], credentials: [options[:user], options[:password]]}})
53
60
  end
54
61
 
55
62
  # Public: Sets the HTTP options that will be used to initialize
@@ -1,3 +1,3 @@
1
1
  module Hyperclient
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -10,7 +10,7 @@ describe Hyperclient do
10
10
 
11
11
  describe 'entry point' do
12
12
  it 'sets the entry point for Hyperclient::Resource' do
13
- api.entry_point 'http://my.api.org'
13
+ api.entry_point {'http://my.api.org'}
14
14
 
15
15
  Hyperclient::Resource.new('/').url.must_include 'http://my.api.org'
16
16
  end
@@ -18,7 +18,7 @@ describe Hyperclient do
18
18
 
19
19
  describe 'entry' do
20
20
  before do
21
- api.entry_point 'http://my.api.org'
21
+ api.entry_point {'http://my.api.org'}
22
22
  end
23
23
 
24
24
  it 'initializes a Resource at the entry point' do
@@ -26,7 +26,7 @@ describe Hyperclient do
26
26
  end
27
27
 
28
28
  it 'also works with entry points that are not in the root' do
29
- api.entry_point 'http://my.api.org/api'
29
+ api.entry_point {'http://my.api.org/api'}
30
30
  api.new.entry.url.must_equal 'http://my.api.org/api'
31
31
  end
32
32
 
@@ -37,13 +37,13 @@ describe Hyperclient do
37
37
 
38
38
  describe 'auth' do
39
39
  it 'sets authentication type' do
40
- api.auth(:digest, nil, nil)
40
+ api.auth{ {type: :digest, user: nil, password: nil} }
41
41
 
42
42
  api.http_options[:http][:auth][:type].must_equal :digest
43
43
  end
44
44
 
45
45
  it 'sets the authentication credentials' do
46
- api.auth(:digest, 'user', 'secret')
46
+ api.auth{ {type: :digest, user: 'user', password: 'secret'} }
47
47
 
48
48
  api.http_options[:http][:auth][:credentials].must_include 'user'
49
49
  api.http_options[:http][:auth][:credentials].must_include 'secret'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  segments:
128
128
  - 0
129
- hash: -1844692704935824375
129
+ hash: 3332679930856512053
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  none: false
132
132
  requirements:
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  segments:
137
137
  - 0
138
- hash: -1844692704935824375
138
+ hash: 3332679930856512053
139
139
  requirements: []
140
140
  rubyforge_project:
141
141
  rubygems_version: 1.8.19