butterfly 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  require "httparty"
2
+ require "active_support/core_ext/class/inheritable_attributes"
2
3
 
3
4
  module Butterfly
4
5
  module Provider
@@ -6,6 +7,25 @@ module Butterfly
6
7
 
7
8
  include ::HTTParty
8
9
 
10
+ class_inheritable_array :required_parameters
11
+
12
+ def initialize(parameters = {})
13
+ self.class.required_parameters.each do |parameter|
14
+ self.send("#{parameter}=", parameters[parameter])
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def self.required_parameter(*parameters)
21
+ self.required_parameters ||= []
22
+ self.required_parameters += parameters
23
+
24
+ parameters.each do |parameter|
25
+ self.send(:attr_accessor, parameter)
26
+ end
27
+ end
28
+
9
29
  end
10
30
  end
11
31
  end
@@ -4,11 +4,7 @@ module Butterfly
4
4
 
5
5
  base_uri "http://api.dribbble.com"
6
6
 
7
- attr_reader :username
8
-
9
- def initialize(username)
10
- @username = username
11
- end
7
+ required_parameter :username
12
8
 
13
9
  def raw
14
10
  @raw ||= self.class.get("/players/#{username}/shots/likes", :format => :json)
@@ -6,11 +6,7 @@ module Butterfly
6
6
 
7
7
  base_uri "http://api.flickr.com/services/rest"
8
8
 
9
- attr_reader :user_id, :api_key
10
-
11
- def initialize(user_id, api_key)
12
- @user_id, @api_key = user_id, api_key
13
- end
9
+ required_parameter :user_id, :api_key
14
10
 
15
11
  def raw
16
12
  @raw ||= self.class.get("/", :format => :json, :query => { :method => "flickr.favorites.getPublicList", :api_key => api_key, :user_id => user_id, :format => "json", :nojsoncallback => "1", :extras => EXTRAS.join(",") })
@@ -4,11 +4,7 @@ module Butterfly
4
4
 
5
5
  base_uri "http://www.tumblr.com/api"
6
6
 
7
- attr_reader :email, :password
8
-
9
- def initialize(email, password)
10
- @email, @password = email, password
11
- end
7
+ required_parameter :email, :password
12
8
 
13
9
  def raw
14
10
  @raw ||= self.class.get("/likes", :format => :xml, :query => { :email => email, :password => password })
@@ -4,11 +4,7 @@ module Butterfly
4
4
 
5
5
  base_uri "http://api.twitter.com/1"
6
6
 
7
- attr_reader :username
8
-
9
- def initialize(username)
10
- @username = username
11
- end
7
+ required_parameter :username
12
8
 
13
9
  def raw
14
10
  @raw ||= self.class.get("/favorites/#{username}.json", :format => :json, :query => { :include_entities => 1 })
@@ -1,3 +1,3 @@
1
1
  module Butterfly
2
- VERSION = "0.0.1"
3
- end
2
+ VERSION = "0.0.2"
3
+ end
@@ -7,7 +7,7 @@ describe Butterfly::Provider::Dribbble do
7
7
  it "should retrieve dribbble likes" do
8
8
  FakeWeb.register_uri(:get, "http://api.dribbble.com/players/testusername/shots/likes", :body => valid_response)
9
9
 
10
- dribbble = Butterfly::Provider::Dribbble.new("testusername")
10
+ dribbble = Butterfly::Provider::Dribbble.new(:username => "testusername")
11
11
 
12
12
  dribbble.likes.first.as_json.should == {
13
13
  "service" => "dribbble",
@@ -7,7 +7,7 @@ describe Butterfly::Provider::Flickr do
7
7
  it "should retrieve flickr likes" do
8
8
  FakeWeb.register_uri(:get, "http://api.flickr.com/services/rest/?method=flickr.favorites.getPublicList&api_key=testapikey&user_id=testuserid&format=json&nojsoncallback=1&extras=description%2Clicense%2Cdate_upload%2Cdate_taken%2Cowner_name%2Cicon_server%2Coriginal_format%2Clast_update%2Cgeo%2Ctags%2Cmachine_tags%2Co_dims%2Cviews%2Cmedia%2Cpath_alias%2Curl_sq%2Curl_t%2Curl_s%2Curl_m%2Curl_z%2Curl_l%2Curl_o", :body => valid_response)
9
9
 
10
- flickr = Butterfly::Provider::Flickr.new("testuserid", "testapikey")
10
+ flickr = Butterfly::Provider::Flickr.new(:user_id => "testuserid", :api_key => "testapikey")
11
11
 
12
12
  flickr.likes.first.as_json.should == {
13
13
  "service" => "flickr",
@@ -7,7 +7,7 @@ describe Butterfly::Provider::Tumblr do
7
7
  it "should retrieve tumblr likes" do
8
8
  FakeWeb.register_uri(:get, "http://www.tumblr.com/api/likes?email=testemail&password=testpassword", :body => valid_response)
9
9
 
10
- tumblr = Butterfly::Provider::Tumblr.new("testemail", "testpassword")
10
+ tumblr = Butterfly::Provider::Tumblr.new(:email => "testemail", :password => "testpassword")
11
11
 
12
12
  tumblr.likes.first.as_json.should == {
13
13
  "service" => "tumblr",
@@ -7,7 +7,7 @@ describe Butterfly::Provider::Twitter do
7
7
  it "should retrieve twitter likes" do
8
8
  FakeWeb.register_uri(:get, "http://api.twitter.com/1/favorites/testusername.json?include_entities=1", :body => valid_response)
9
9
 
10
- twitter = Butterfly::Provider::Twitter.new("testusername")
10
+ twitter = Butterfly::Provider::Twitter.new(:username => "testusername")
11
11
 
12
12
  twitter.likes.first.as_json.should == {
13
13
  "service" => "twitter",
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: butterfly
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Steve Hoeksema