behance 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Amed Rodriguez
1
+ Copyright (c) 2012-2013 Tractical
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
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.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,24 +1,89 @@
1
- # Behance
1
+ # The Behance Ruby Gem
2
2
 
3
- TODO: Write a gem description
3
+ A Ruby wrapper for the Behance API.
4
+
5
+ More information about the API capabilities can be found [here][api].
6
+
7
+ [api]: http://www.behance.net/devi
4
8
 
5
9
  ## Installation
6
10
 
7
- Add this line to your application's Gemfile:
11
+ $ gem install behance
8
12
 
9
- gem 'behance'
13
+ ## API Usage Examples
10
14
 
11
- And then execute:
15
+ First of all, you will need to get an access token [here][register].
12
16
 
13
- $ bundle
17
+ [register]: http://www.behance.net/dev/register
14
18
 
15
- Or install it yourself as:
19
+ Once you get it, you'll be able to start playing
16
20
 
17
- $ gem install behance
21
+ # initializing the client
22
+ $ client = Behance::Client.new(access_token: "access-token")
23
+
24
+ ### Projects
25
+
26
+ [Search for projects][projects]
27
+
28
+ [projects]: http://www.behance.net/dev/api/endpoints/1#projects-get-10
29
+
30
+ $ client.projects
31
+ $ client.projects(city: "San Francisco", state: "California", field: "branding")
32
+
33
+ [Get the information and content of a project][project]
34
+
35
+ [project]: http://www.behance.net/dev/api/endpoints/1#projects-get-4
36
+
37
+ $ client.project(5133725)
38
+
39
+ [Get the comments for a project][project_comments]
40
+
41
+ [project_comments]: http://www.behance.net/dev/api/endpoints/1#projects-get-5
42
+
43
+ $ client.project_comments(5133725)
44
+
45
+ ### Users
46
+
47
+ [Search for users][users]
48
+
49
+ [users]: http://www.behance.net/dev/api/endpoints/2#users-get-9
18
50
 
19
- ## Usage
51
+ $ client.users
52
+ $ client.users(state: "California", city: "San Francisco")
20
53
 
21
- TODO: Write usage instructions here
54
+ [Get basic information about an user][user]
55
+
56
+ [user]: http://www.behance.net/dev/api/endpoints/2#users-get-1
57
+
58
+ $ client.user(920309)
59
+ $ client.user("foo")
60
+
61
+ [Get the projects published by an user][user_projects]
62
+
63
+ [user_projects]: http://www.behance.net/dev/api/endpoints/2#users-get-2
64
+
65
+ $ client.user_projects(920309)
66
+ $ client.user_projects("jonkap1")
67
+ $ client.user_projects("jonkap1", page: 2, sort: "views")
68
+
69
+ [Get the works-in-progress published by an user][user_wips]
70
+
71
+ [user_wips]: http://www.behance.net/dev/api/endpoints/2#users-get-3
72
+
73
+ $ client.user_wips(920309)
74
+ $ client.user_wips(920309, page: 2)
75
+ $ client.user_wips("jonkap1", sort: "comments", page: 3)
76
+
77
+ [Get a list of user's recently appreciated projects][user_appreciations]
78
+
79
+ [user_appreciations]: http://www.behance.net/dev/api/endpoints/2#users-get-13
80
+
81
+ $ client.user_appreciations(920309)
82
+ $ client.user_appreciations("jonkap1")
83
+
84
+ ### Works in Progress
85
+
86
+ **This is an actual work in progress ;-)**
22
87
 
23
88
  ## Contributing
24
89
 
@@ -27,3 +92,10 @@ TODO: Write usage instructions here
27
92
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
93
  4. Push to the branch (`git push origin my-new-feature`)
29
94
  5. Create new Pull Request
95
+
96
+ ## Copyright
97
+
98
+ Copyright (c) 2012-2013 Tractical.
99
+ See [LICENSE][license] for details.
100
+
101
+ [license]: https://github.com/tractical/behance/blob/master/LICENSE.txt
@@ -17,6 +17,9 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency 'faraday', '~> 0.8.4'
21
- gem.add_development_dependency 'rspec', '~> 2.6'
20
+ gem.add_runtime_dependency 'faraday', '~> 0.8.4'
21
+ gem.add_runtime_dependency 'faraday_middleware', '~> 0.8'
22
+ gem.add_runtime_dependency 'json', '1.7.5'
23
+ gem.add_development_dependency 'webmock', '~> 1.8.10'
24
+ gem.add_development_dependency 'rspec', '~> 2.6'
22
25
  end
@@ -1,5 +1,2 @@
1
- require "behance/version"
2
-
3
- module Behance
4
- # Your code goes here...
5
- end
1
+ require File.expand_path('../behance/version', __FILE__)
2
+ require File.expand_path('../behance/client', __FILE__)
@@ -0,0 +1,58 @@
1
+ require File.expand_path('../project', __FILE__)
2
+ require File.expand_path('../user', __FILE__)
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+
6
+ # Public: Methods handled by the Client connection.
7
+ module Behance
8
+
9
+ class Client
10
+
11
+ API_URL = "http://www.behance.net/v2/"
12
+
13
+ include Behance::Client::Project
14
+ include Behance::Client::User
15
+
16
+ attr_accessor :access_token, :connection
17
+
18
+ # Public: Initialize a client for API requests.
19
+ #
20
+ # options - The Hash with options required by Behance:
21
+ # :access_token - Behance API token.
22
+ #
23
+ # Examples
24
+ #
25
+ # @client = Behance::Client.new(access_token: "aKlie12MCJa5")
26
+ #
27
+ # Returns a Faraday instance object.
28
+ def initialize(options={})
29
+ @access_token = options[:access_token]
30
+ @connection = Faraday.new(:url => Behance::Client::API_URL) do |b|
31
+ b.adapter Faraday.default_adapter
32
+ b.use FaradayMiddleware::ParseJson
33
+ end
34
+ end
35
+
36
+ # Public: Makes a http request to the API.
37
+ #
38
+ # path - A String that represents the endpoint path.
39
+ # options - Hash of parameters to pass along.
40
+ #
41
+ # Examples
42
+ #
43
+ # request("users/1")
44
+ # request("projects", page: 2)
45
+ #
46
+ # Returns a response body from the API.
47
+ def request(path, options={})
48
+ response = @connection.get do |req|
49
+ req.url path
50
+ req.params[:api_key] = @access_token
51
+ options.each do |key, val|
52
+ req.params[key] = val
53
+ end
54
+ end
55
+ response.body
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,68 @@
1
+ # Projects Endpoints.
2
+ module Behance
3
+ class Client
4
+ module Project
5
+ # Public: Search for projects.
6
+ #
7
+ # options - The Hash of options that the API would expect:
8
+ # :q - Free text query string.
9
+ # :sort - The order the results are returned in.
10
+ # Possible values: featured_date (default), apprecia-
11
+ # tions, views, comments,
12
+ # published_date.
13
+ # :time - Limits the search by time.
14
+ # Possible values: all (default), today, week, month.
15
+ # :field - Limits the search by creative field.
16
+ # Accepts a URL-encoded field name from the list of
17
+ # defined creative fields.
18
+ # :country - Limits the search by a 2-letter FIPS country code.
19
+ # :state - Limits the search by state or province name.
20
+ # :city - Limits the search by city name.
21
+ # :page - The page number of the results, always starting
22
+ # with 1.
23
+ # :tags - Limits the search by tags.
24
+ # Accepts one tag name or a pipe-separated list of
25
+ # tag names.
26
+ #
27
+ # Examples
28
+ #
29
+ # @client.projects
30
+ # @client.projects(q: "Freelance", state: "CA", field: "Branding")
31
+ #
32
+ # Returns an array of projects in JSON format.
33
+ def projects(options={})
34
+ request("projects", options)["projects"]
35
+ end
36
+
37
+ # Public: Get the information and content of a project.
38
+ #
39
+ # project_id - the ID (Integer) of the project.
40
+ #
41
+ # Examples
42
+ #
43
+ # @client.project(1123)
44
+ #
45
+ # Returns a single project in JSON format.
46
+ def project(project_id)
47
+ request("projects/#{project_id}")["project"]
48
+ end
49
+
50
+ # Public: Get the comments for a project
51
+ #
52
+ # project_id - The ID (Integer) of the project.
53
+ # options - The Hash of options that the API would expect:
54
+ # :page - The page number of the results, always
55
+ # starting with 1.
56
+ #
57
+ # Examples
58
+ #
59
+ # @client.project_comments(1)
60
+ # @client.project_comments(1, page: 1)
61
+ #
62
+ # Returns an array of project comments in JSON format.
63
+ def project_comments(project_id, options={})
64
+ request("projects/#{project_id}/comments", options)["comments"]
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,111 @@
1
+ # Users Endpoints.
2
+ module Behance
3
+ class Client
4
+ module User
5
+ # Public: Search for users.
6
+ #
7
+ # options - The Hash of options that the API would expect:
8
+ # :q - Free text query string.
9
+ # :field - Limits the search by creative field.
10
+ # Accepts a URL-encoded field name from the list of
11
+ # defined creative fields.
12
+ # :country - Limits the search by a 2-letter FIPS country code.
13
+ # :state - Limits the search by state or province name.
14
+ # :city - Limits the search by city name.
15
+ # :page - The page number of the results, always starting
16
+ # with 1.
17
+ # :sort - The order the results are returned in.
18
+ # Possible values: featured_date (default), apprecia-
19
+ # tions, views, comments,
20
+ # published_date, followed.
21
+ # :tags - Limits the search by tags.
22
+ # Accepts one tag name or a pipe-separated list of
23
+ # tag names.
24
+ #
25
+ # Examples
26
+ #
27
+ # @client.users
28
+ # @client.users(q: "Juan", state: "California", :tags "freelance")
29
+ #
30
+ # Returns an array of users in JSON format.
31
+ def users(options={})
32
+ request("users", options)["users"]
33
+ end
34
+
35
+ # Public: Get basic information about a user.
36
+ #
37
+ # user - can be an ID (Integer) or username (String).
38
+ #
39
+ # Examples
40
+ #
41
+ # @client.user(1)
42
+ # @client.user("foo")
43
+ #
44
+ # Returns a single user object.
45
+ def user(user)
46
+ request("users/#{user}")["user"]
47
+ end
48
+
49
+ # Public: Get the projects published by an user.
50
+ #
51
+ # user - Can be an ID (Integer) or username (String)
52
+ # options - The Hash of options that the API would expect:
53
+ # :sort - The order the results are returned in.
54
+ # Possible values: featured_date (default), apprecia-
55
+ # tions, views, comments, published_date.
56
+ # :time - Limits the search by time.
57
+ # Possible values: all (default), today, week, month.
58
+ # :page - The page number of the results, always starting
59
+ # with 1.
60
+ #
61
+ # Examples
62
+ #
63
+ # @client.user_projects(1)
64
+ # @client.user_projects("foo")
65
+ # @client.user_projects("foo", page: 2, sort: "views")
66
+ #
67
+ # Returns an array of projects published an user in JSON format.
68
+ def user_projects(user, options={})
69
+ request("users/#{user}/projects", options)["projects"]
70
+ end
71
+
72
+ # Public: Get the works-in-progress published by a user.
73
+ #
74
+ # user - can be an ID (Integer) or username (String).
75
+ # options - The Hash of options that the API would expect:
76
+ # :sort - The order the results are returned in.
77
+ # Possible values: featured_date (default), apprecia-
78
+ # tions, views, comments, published_date.
79
+ # :time - Limits the search by time. Possible values: all
80
+ # (default), today, week, month.
81
+ # :page - The page number of the results, always starting
82
+ # with 1.
83
+ #
84
+ # Examples
85
+ #
86
+ # @client.user_wips(1)
87
+ # @client.user_wips(1, page: 2)
88
+ # @client.user_wips("foo", sort: "comments", page: 3)
89
+ #
90
+ # Returns an array of work-in-progress of an user in JSON format.
91
+ def user_wips(user, options={})
92
+ request("users/#{user}/wips", options)["wips"]
93
+ end
94
+
95
+ # Public: Get a list of user's recently appreciated projects.
96
+ #
97
+ # user - can be an ID (Integer) or username (String).
98
+ #
99
+ # Examples
100
+ #
101
+ # @client.user_appreciations(1)
102
+ # @client.user_appreciations("foo")
103
+ #
104
+ # Returns an array of user's recently appreciated projects in JSON
105
+ # format.
106
+ def user_appreciations(user)
107
+ request("users/#{user}/appreciations")["appreciations"]
108
+ end
109
+ end
110
+ end
111
+ end
@@ -1,3 +1,3 @@
1
1
  module Behance
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Behance::Client do
4
+
5
+ before do
6
+ @client = Behance::Client.new(:access_token => "abc123")
7
+ end
8
+
9
+ it "initializes properly" do
10
+ @client.should be_a_kind_of Behance::Client
11
+ end
12
+
13
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe Behance::Client::Project do
4
+
5
+ before(:all) do
6
+ @client = Behance::Client.new(:access_token => "abc123")
7
+ end
8
+
9
+ before do
10
+ @options = { api_key: @client.access_token }
11
+ end
12
+
13
+ describe "#projects" do
14
+ context "without parameters" do
15
+ before do
16
+ stub_get("projects").with(query: @options).
17
+ to_return(body: fixture("projects.json"))
18
+ @projects = @client.projects
19
+ end
20
+
21
+ it "makes a http request" do
22
+ a_get("projects").
23
+ with(query: @options).should have_been_made
24
+ end
25
+
26
+ it "gets a list of projects" do
27
+ @projects.size.should == 7
28
+ end
29
+ end
30
+
31
+ context "with parameters" do
32
+ before do
33
+ @options.merge!(q: "yolo", page: 2)
34
+ stub_get("projects").with(query: @options).
35
+ to_return(body: fixture("projects.json"))
36
+ end
37
+
38
+ it "gets a list of projects" do
39
+ @client.projects(@options).size.should == 7
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "#project" do
45
+ before do
46
+ stub_get("projects/4889175").with(query: @options).
47
+ to_return(body: fixture("project.json"))
48
+ @project = @client.project(4889175)
49
+ end
50
+
51
+ it "makes a http request" do
52
+ a_get("projects/4889175").
53
+ with(query: @options).should have_been_made
54
+ end
55
+
56
+ it "gets a single project" do
57
+ @project["id"].should == 4889175
58
+ end
59
+ end
60
+
61
+ describe "#project_comments" do
62
+ before do
63
+ stub_get("projects/1/comments").with(query: @options).
64
+ to_return(body: fixture("project_comments.json"))
65
+ @comments = @client.project_comments(1)
66
+ end
67
+
68
+ it "makes a http request" do
69
+ a_get("projects/1/comments").
70
+ with(query: @options).should have_been_made
71
+ end
72
+
73
+ it "gets a list of comments" do
74
+ @comments.size.should == 9
75
+ end
76
+ end
77
+ end