zunnit 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zunnit (0.0.3)
4
+ zunnit (0.0.4)
5
5
  faraday
6
6
 
7
7
  GEM
data/lib/zunnit/api.rb CHANGED
@@ -9,49 +9,49 @@ module Zunnit
9
9
 
10
10
  yield self if block_given?
11
11
  end
12
-
13
- # Connection object
14
- def connection
15
- @connection ||= Faraday.new(:url => "#{Zunnit::URL}#{self.client}")
16
- end
17
- private :connection
18
-
19
- def params_for(options={})
20
- return {
21
- :api_key => self.key
22
- }.merge(options)
23
- end
24
-
25
- # Make a request to Zunnit's API
26
- def request(http_method, action, options={})
27
- # Raise error if the actions is invalid
28
- unless Zunnit.actions[action]
29
- raise "Invalid action \"#{action}\""
30
- end
31
-
32
- # Raise error if the http method is invalid
33
- unless [:get, :post].include? http_method
34
- raise "Invalid http_method \"#{http_method}\""
35
- end
36
-
37
- # Make the Request
38
- action_url = Zunnit.actions[action]
39
- response = connection.send(http_method) do |req|
40
- req.url(action_url)
41
- req.params = params_for options
42
- end
43
-
44
- response
45
- end
46
-
12
+
47
13
  # Make a GET request to Zunnit's API
48
14
  def get(action, options={})
49
- self.request(:get, action, options)
15
+ request(:get, action, options)
50
16
  end
51
17
 
52
18
  # Make a POST request to Zunnit's API
53
19
  def post(action, options={})
54
- self.request(:post, action, options)
55
- end
20
+ request(:post, action, options)
21
+ end
22
+
23
+ private
24
+ def connection
25
+ @connection ||= Faraday.new(:url => Zunnit::URL)
26
+ end
27
+
28
+ def params_for(options={})
29
+ return {
30
+ :api_key => self.key
31
+ }.merge(options)
32
+ end
33
+
34
+ # Make a request to Zunnit's API
35
+ def request(http_method, action, options={})
36
+ # Raise error if the actions is invalid
37
+ unless Zunnit.actions[action]
38
+ raise "Invalid action \"#{action}\""
39
+ end
40
+
41
+ # Raise error if the http method is invalid
42
+ unless [:get, :post].include? http_method
43
+ raise "Invalid http_method \"#{http_method}\""
44
+ end
45
+
46
+ # Make the Request
47
+ action_url = "/#{client}#{Zunnit.actions[action]}"
48
+ response = connection.send(http_method) do |req|
49
+ req.url(action_url)
50
+ req.params = params_for options
51
+ end
52
+
53
+ # return HASH for body JSON
54
+ JSON response.body, :symbolize_names => true
55
+ end
56
56
  end
57
57
  end
data/lib/zunnit/setup.rb CHANGED
@@ -15,11 +15,13 @@ module Zunnit
15
15
  :action_items_add => "/action/items/add",
16
16
  :action_items_rate => "/action/items/rate",
17
17
  :action_items_view => "/action/items/view",
18
- :action_user_follow => "/action/user/follow"
18
+ :action_user_follow => "/action/user/follow"
19
19
  }
20
20
 
21
21
  def self.setup
22
22
  self.actions = ACTIONS
23
+
23
24
  yield self
25
+ self
24
26
  end
25
27
  end
data/lib/zunnit/utils.rb CHANGED
@@ -1,7 +1,8 @@
1
- module Zunnit::Utils
2
- def mattr_accessor *attrs
3
- attrs.each do |attr|
4
- module_eval %[
1
+ module Zunnit
2
+ module Utils
3
+ def mattr_accessor *attrs
4
+ attrs.each do |attr|
5
+ module_eval %[
5
6
  def self.#{attr.to_s}=(value)
6
7
  @#{attr.to_s} = value
7
8
  end
@@ -9,7 +10,8 @@ module Zunnit::Utils
9
10
  def self.#{attr.to_s}
10
11
  @#{attr.to_s}
11
12
  end
12
- ]
13
+ ]
14
+ end
13
15
  end
14
16
  end
15
17
  end
@@ -1,4 +1,4 @@
1
1
  module Zunnit
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
4
4
 
data/lib/zunnit.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'rubygems'
3
3
  require "faraday"
4
-
4
+ require "json"
5
5
 
6
6
  # Local Libs
7
7
  $:.unshift(File.dirname(__FILE__) + '/../../lib')
data/spec/zunnit_spec.rb CHANGED
@@ -7,8 +7,8 @@ describe Zunnit do
7
7
  describe "get" do
8
8
  it "should return related items" do
9
9
  zunnit = Zunnit::Api.new
10
- response = zunnit.get(:related_items, {:item_id=>"20275919"})
11
- response.should == 200
10
+ response = zunnit.get(:related_items, {:item_id=> "20275919"})
11
+ response[:status].should == 200
12
12
  end
13
13
  end
14
14
  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.4
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Marcelo Eden