f00px 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # F00px
2
2
 
3
- 500px api ruby gem
3
+ 500px api ruby gem [![Build Status](https://travis-ci.org/500px/f00px.png)](https://travis-ci.org/500px/f00px)
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,16 +20,42 @@ Or install it yourself as:
20
20
 
21
21
  Add this code to some initializer:
22
22
 
23
- F00px.configure do |config|
24
- config.consumer_key = __consumer_key__
25
- config.consumer_secret = __consumer_secret__
26
- config.token = __token__
27
- config.token_secret = __token_secret__
28
- end
23
+ ```ruby
24
+ F00px.configure do |config|
25
+ config.consumer_key = __consumer_key__
26
+ config.consumer_secret = __consumer_secret__
27
+ config.token = __token__
28
+ config.token_secret = __token_secret__
29
+ end
30
+ ```
29
31
 
30
32
  Then just use the api:
31
33
 
32
- response = F00px.get('/users/1')
34
+ ```ruby
35
+ response = F00px.get('users/1')
36
+ puts response.body
37
+ ```
38
+
39
+ You also can create multiple clients.
40
+
41
+ With oauth
42
+ ```ruby
43
+ client = F00px::Client.new
44
+ client.token = '__client_token__'
45
+ client.token_secret = '__client_token_secret__'
46
+
47
+ response = client.get('users')
48
+ puts response.body
49
+ ```
50
+
51
+ With xauth
52
+ ```ruby
53
+ client = F00px::Client.new
54
+ client.xauth('arthurnn', '**password**')
55
+
56
+ response = client.get('users')
57
+ puts response.body
58
+ ```
33
59
 
34
60
  ## Contributing
35
61
 
data/lib/#f00px.rb# ADDED
@@ -0,0 +1,35 @@
1
+ require "f00px/version"
2
+ require "cgi"
3
+ require "faraday_middleware"
4
+ require "typhoeus"
5
+ require "typhoeus/adapters/faraday"
6
+ require "f00px/error"
7
+ require "f00px/authentication"
8
+ require "f00plib/f00px/version.rbx/configuration"
9
+ require "f00px/connection"
10
+ require "f00px/request"
11
+ require "f00px/api"
12
+ require "f00px/client"
13
+
14
+
15
+ module F00px
16
+
17
+ class << self
18
+
19
+ include Configuration
20
+
21
+ def client
22
+ @client ||= F00px::Client.new
23
+ end
24
+
25
+ private
26
+
27
+ def method_missing(method_name, *args, &block)
28
+ return super unless client.respond_to?(method_name)
29
+ client.send(method_name, *args, &block)
30
+ end
31
+
32
+ end
33
+
34
+
35
+ end
@@ -0,0 +1,29 @@
1
+ module F00px
2
+ module ParametersBuilder
3
+
4
+ def initialize
5
+ @params = {}
6
+ end
7
+
8
+ def images(*images)
9
+ @params[:image_size] = Array(images)
10
+ self
11
+ end
12
+
13
+ def include_states(v)
14
+ @params[:include_states] = !!v
15
+ self
16
+ end
17
+
18
+ def options(opts)
19
+ images(*opts[:images]) if opts[:images]
20
+ @params.merge!(opts)
21
+ self
22
+ end
23
+
24
+ def build
25
+ @params
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,57 @@
1
+ module F00px
2
+ module Api
3
+ module Photos
4
+
5
+ def popular(*args)
6
+ options = get_options(args)
7
+ builder = args.first
8
+ builder ||= Builder.new
9
+
10
+ params = builder
11
+ .feature('popular')
12
+ .options(options)
13
+ .build
14
+
15
+ self.get('photos', params)
16
+ end
17
+
18
+ def user_photos(*args)
19
+ options = get_options(args)
20
+ user_id, builder = args
21
+ builder ||= Builder.new
22
+
23
+ params = builder
24
+ .feature('user')
25
+ .user_id(user_id)
26
+ .options(options)
27
+ .build
28
+
29
+ self.get('photos', params)
30
+ end
31
+
32
+ class Builder
33
+ include ParametersBuilder
34
+
35
+ def feature(f)
36
+ @params[:feature] = f
37
+ self
38
+ end
39
+
40
+ def user_id(uid)
41
+ @params[:user_id] = uid
42
+ self
43
+ end
44
+ end
45
+
46
+ private
47
+ def get_options(args)
48
+ if args.last.is_a?(Hash)
49
+ options = args.pop
50
+ else
51
+ options = {}
52
+ end
53
+ options
54
+ end
55
+ end
56
+ end
57
+ end
data/lib/f00px/api.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "f00px/api/parameters_builder"
2
+ require "f00px/api/photos"
data/lib/f00px/client.rb CHANGED
@@ -6,6 +6,8 @@ module F00px
6
6
  include Connection
7
7
  include Request
8
8
 
9
+ include Api::Photos
10
+
9
11
  def self.configure(&block)
10
12
  Client.new.configure(&block)
11
13
  end
@@ -15,7 +17,5 @@ module F00px
15
17
  settings[key] = options[key] || F00px.__send__("#{key}".to_sym)
16
18
  end
17
19
  end
18
-
19
-
20
20
  end
21
21
  end
@@ -15,6 +15,8 @@ module F00px
15
15
  option :logger
16
16
  option :user_id
17
17
 
18
+ option :faraday_adapter, default: Faraday.default_adapter
19
+
18
20
  def self.included(base)
19
21
  end
20
22
 
@@ -26,15 +26,9 @@ module F00px
26
26
 
27
27
  builder.use Faraday::Response::Logger, logger if logger?
28
28
 
29
- builder.adapter connection_adapter
29
+ builder.adapter faraday_adapter
30
30
  end
31
31
  end
32
32
 
33
- private
34
-
35
- def connection_adapter
36
- :typhoeus
37
- end
38
-
39
33
  end
40
34
  end
@@ -29,26 +29,37 @@ module F00px
29
29
  # Runs all queued requests. This method will block until all requests are complete.
30
30
  # As requests complete their callbacks will be executed.
31
31
  def run!
32
- conn = @connection
33
-
34
- responses = {}
35
- conn.in_parallel do
32
+ execute_in_parallel do
36
33
  @queued_requests.each do |callback|
37
- method, url, params = callback.info
38
- params ||= {}
39
- params[:auth_user_id] = user_id if user_id
40
-
41
- response = conn.run_request(method, url, params, {})
34
+ execute_request(callback)
35
+ end
36
+ end
37
+ ensure
38
+ @queued_requests = []
39
+ end
42
40
 
43
- response.on_complete do
44
- callback.perform(response)
45
- end
41
+ private
46
42
 
43
+ def execute_in_parallel
44
+ if @connection.in_parallel?
45
+ @connection.in_parallel do
46
+ yield
47
47
  end
48
+ else
49
+ yield
48
50
  end
51
+ end
49
52
 
50
- ensure
51
- @queued_requests = []
53
+ def execute_request(callback)
54
+ method, url, params = callback.info
55
+ params ||= {}
56
+ params[:auth_user_id] = user_id if user_id
57
+
58
+ response = @connection.run_request(method, url, params, {})
59
+
60
+ response.on_complete do
61
+ callback.perform(response)
62
+ end
52
63
  end
53
64
 
54
65
  end
data/lib/f00px/request.rb CHANGED
@@ -8,21 +8,21 @@ module F00px
8
8
  queue = Request::Runner.new(connection)
9
9
  queue.user_id = user_id if user_id?
10
10
  queue.consumer_key = consumer_key if consumer_key?
11
- yield(queue)
11
+ queue.instance_eval(&block)
12
12
  queue.run!
13
13
  end
14
14
 
15
15
  def get(url, params = {})
16
- queue do |q|
17
- q.get(url, params).complete do |response|
16
+ queue do
17
+ get(url, params).complete do |response|
18
18
  return response
19
19
  end
20
20
  end
21
21
  end
22
22
 
23
23
  def post(url, params = {})
24
- queue do |q|
25
- q.post(url, params).complete do |response|
24
+ queue do
25
+ post(url, params).complete do |response|
26
26
  return response
27
27
  end
28
28
  end
data/lib/f00px/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module F00px
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/f00px.rb CHANGED
@@ -1,13 +1,12 @@
1
1
  require "f00px/version"
2
2
  require "cgi"
3
3
  require "faraday_middleware"
4
- require "typhoeus"
5
- require "typhoeus/adapters/faraday"
6
4
  require "f00px/error"
7
5
  require "f00px/authentication"
8
6
  require "f00px/configuration"
9
7
  require "f00px/connection"
10
8
  require "f00px/request"
9
+ require "f00px/api"
11
10
  require "f00px/client"
12
11
 
13
12
  module F00px
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: f00px
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-10 00:00:00.000000000 Z
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday_middleware
@@ -27,22 +27,6 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.9.0
30
- - !ruby/object:Gem::Dependency
31
- name: typhoeus
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: 0.5.4
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 0.5.4
46
30
  - !ruby/object:Gem::Dependency
47
31
  name: simple_oauth
48
32
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +50,10 @@ executables: []
66
50
  extensions: []
67
51
  extra_rdoc_files: []
68
52
  files:
53
+ - lib/#f00px.rb#
54
+ - lib/f00px/api/parameters_builder.rb
55
+ - lib/f00px/api/photos.rb
56
+ - lib/f00px/api.rb
69
57
  - lib/f00px/authentication.rb
70
58
  - lib/f00px/client.rb
71
59
  - lib/f00px/configuration/options.rb
@@ -102,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
90
  version: 1.3.6
103
91
  requirements: []
104
92
  rubyforge_project: f00px
105
- rubygems_version: 1.8.24
93
+ rubygems_version: 1.8.25
106
94
  signing_key:
107
95
  specification_version: 3
108
96
  summary: 500px api rubygem