zunnit 0.0.2 → 0.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.
- data/Gemfile.lock +9 -1
- data/lib/zunnit/version.rb +1 -1
- data/lib/zunnit/zunnit.rb +58 -0
- data/lib/zunnit.rb +8 -3
- data/spec/spec_helper.rb +1 -1
- data/spec/zunnit_spec.rb +13 -0
- data/zunnit.gemspec +3 -0
- metadata +15 -8
- data/.Gemfile.swp +0 -0
- data/.Rakefile.swp +0 -0
- data/lib/.zunnit.rb.swp +0 -0
- data/lib/zunnit/.version.rb.swp +0 -0
- data/spec/.spec_helper.rb.swp +0 -0
data/Gemfile.lock
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zunnit (0.0.
|
4
|
+
zunnit (0.0.2)
|
5
|
+
faraday
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: http://rubygems.org/
|
8
9
|
specs:
|
10
|
+
addressable (2.2.6)
|
9
11
|
diff-lcs (1.1.2)
|
12
|
+
faraday (0.7.2)
|
13
|
+
addressable (~> 2.2.6)
|
14
|
+
multipart-post (~> 1.1.0)
|
15
|
+
rack (>= 1.1.0, < 2)
|
16
|
+
multipart-post (1.1.2)
|
17
|
+
rack (1.3.0)
|
10
18
|
rspec (2.6.0)
|
11
19
|
rspec-core (~> 2.6.0)
|
12
20
|
rspec-expectations (~> 2.6.0)
|
data/lib/zunnit/version.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
module Zunnit
|
2
|
+
# Fixed constants
|
3
|
+
API_URL = "http://api.zunnit.com/"
|
4
|
+
API_ACTIONS = {
|
5
|
+
:related_items => "/related/items",
|
6
|
+
:recommendation_items_for_user => "/recommendation/items/for_user",
|
7
|
+
:recommendation_groups_for_user => "/recommendation/groups/for_user",
|
8
|
+
:recommendation_users_for_user => "/recommendation/users/for_user",
|
9
|
+
:recommendation_users_for_item => "/recommendation/users/for_item",
|
10
|
+
:recommendation_tags_for_item => "/recommendation/tags/for_item",
|
11
|
+
:recommendation_cluster_for_item => "/recommendation/cluster/for_item",
|
12
|
+
:action_items_add => "/action/items/add",
|
13
|
+
:action_items_rate => "/action/items/rate",
|
14
|
+
:action_items_view => "/action/items/view",
|
15
|
+
:action_user_follow => "/action/user/follow"
|
16
|
+
}
|
17
|
+
|
18
|
+
# Configurable constants
|
19
|
+
API_CLIENT = "busk"
|
20
|
+
API_KEY = "busk"
|
21
|
+
API_VERSION = "1.0"
|
22
|
+
|
23
|
+
class << self
|
24
|
+
# API URL for action
|
25
|
+
def url_for(action)
|
26
|
+
raise "Invalid action '#{action}'" unless API_ACTIONS[action]
|
27
|
+
|
28
|
+
# Generate the URL
|
29
|
+
url = "#{API_URL}#{API_CLIENT}#{API_ACTIONS[action]}?api_key=#{API_KEY}"
|
30
|
+
url
|
31
|
+
end
|
32
|
+
|
33
|
+
# Make a request to Zunnit's API
|
34
|
+
def request(http_method, action, options={})
|
35
|
+
connection = Faraday.new(:url => self.url_for(action))
|
36
|
+
response = case http_method.to_sym
|
37
|
+
when :get
|
38
|
+
connection.get { |req| req.params = options }
|
39
|
+
when :post
|
40
|
+
connection.post { |req| req.params = options }
|
41
|
+
else
|
42
|
+
raise "Invalid http_method \"#{http_method}\""
|
43
|
+
end
|
44
|
+
|
45
|
+
response
|
46
|
+
end
|
47
|
+
|
48
|
+
# Make a GET request to Zunnit's API
|
49
|
+
def get(action, options={})
|
50
|
+
self.request(:get, action, options)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Make a POST request to Zunnit's API
|
54
|
+
def post(action, options={})
|
55
|
+
self.request(:post, action, options)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/zunnit.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/zunnit_spec.rb
CHANGED
@@ -3,5 +3,18 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
|
4
4
|
describe Zunnit do
|
5
5
|
|
6
|
+
describe "url_for" do
|
7
|
+
it "return url for related item" do
|
8
|
+
url = Zunnit.url_for(:related_items)
|
9
|
+
url.should == "http://api.zunnit.com/busk/related/items?api_key=busk"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "get" do
|
14
|
+
it "should return related items" do
|
15
|
+
response = Zunnit.get(:related_items, {:item_id=>"20275919"})
|
16
|
+
response.status.should == 200
|
17
|
+
end
|
18
|
+
end
|
6
19
|
end
|
7
20
|
|
data/zunnit.gemspec
CHANGED
@@ -19,6 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
+
# Dependencies
|
23
|
+
s.add_dependency "faraday"
|
24
|
+
|
22
25
|
# Development Dependencies
|
23
26
|
s.add_development_dependency "rspec"
|
24
27
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: zunnit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Marcelo Eden
|
@@ -14,7 +14,7 @@ date: 2011-06-20 00:00:00 -03:00
|
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
17
|
+
name: faraday
|
18
18
|
prerelease: false
|
19
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
@@ -22,8 +22,19 @@ dependencies:
|
|
22
22
|
- - ">="
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: "0"
|
25
|
-
type: :
|
25
|
+
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
27
38
|
description: Gem do access zunnit's API
|
28
39
|
email:
|
29
40
|
- marcelo@busk.com
|
@@ -35,18 +46,14 @@ extra_rdoc_files: []
|
|
35
46
|
|
36
47
|
files:
|
37
48
|
- .DS_Store
|
38
|
-
- .Gemfile.swp
|
39
|
-
- .Rakefile.swp
|
40
49
|
- .gitignore
|
41
50
|
- Gemfile
|
42
51
|
- Gemfile.lock
|
43
52
|
- README
|
44
53
|
- Rakefile
|
45
|
-
- lib/.zunnit.rb.swp
|
46
54
|
- lib/zunnit.rb
|
47
|
-
- lib/zunnit/.version.rb.swp
|
48
55
|
- lib/zunnit/version.rb
|
49
|
-
-
|
56
|
+
- lib/zunnit/zunnit.rb
|
50
57
|
- spec/spec_helper.rb
|
51
58
|
- spec/zunnit_spec.rb
|
52
59
|
- zunnit.gemspec
|
data/.Gemfile.swp
DELETED
Binary file
|
data/.Rakefile.swp
DELETED
Binary file
|
data/lib/.zunnit.rb.swp
DELETED
Binary file
|
data/lib/zunnit/.version.rb.swp
DELETED
Binary file
|
data/spec/.spec_helper.rb.swp
DELETED
Binary file
|