wonderfl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 wellflat
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,72 @@
1
+ = wonderfl
2
+
3
+ == description:
4
+
5
+ Ruby wrapper for the wonderfl API
6
+
7
+ see also: http://wonderfl.net/apis
8
+
9
+ == note:
10
+
11
+ Requires api key, get yours from your account page.
12
+
13
+ http://wonderfl.net/account/api_keys/create
14
+
15
+ if you are not registered then you can get account easily.
16
+
17
+ == installation:
18
+
19
+ gem install wonderfl
20
+
21
+ == usage:
22
+
23
+ Create a wonderfl API client using your api_key as follows:
24
+
25
+ client = Wonderfl::Client.new('your api_key')
26
+ or
27
+ client = Wonderfl::Client.new
28
+ client.api_key = 'your api_key'
29
+
30
+ You can then use that client to retrieve information about user or posted codes as so:
31
+
32
+ client.get_user('user_name') #=> Wonderfl::User
33
+ client.get_user_codes('user_name') #=> Wonderfl::UserCodes (Wonderfl::Code collection)
34
+ client.get_code('code_id') #=> Wonderfl::Code
35
+ client.get_code_forks('code_id') #=> Wonderfl::CodeForks (Wonderfl::Code collection)
36
+
37
+ You can then get all the information required from that object.
38
+ for example, takes code informations.
39
+
40
+ code = client.get_code('m3d6') #=> Wonderfl::Code
41
+ code.compile_ok #=> 1
42
+ code.favorite_count #=> 24
43
+ code.forked_count #=> 11
44
+ code.license #=> 'MIT'
45
+ code.swf #=> 'http://swf.wonderfl.net/swf/usercode/,,,.swf'
46
+ code.thumbnail #=> 'http://wonderfl.net/images/capture/,,,.jpg'
47
+ code.title #=> 'flash on 2010-08-15'
48
+ ...
49
+
50
+ == license:
51
+
52
+ (The MIT License)
53
+
54
+ Copyright (c) 2010 wellflat
55
+
56
+ Permission is hereby granted, free of charge, to any person obtaining a copy
57
+ of this software and associated documentation files (the "Software"), to deal
58
+ in the Software without restriction, including without limitation the rights
59
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
60
+ copies of the Software, and to permit persons to whom the Software is
61
+ furnished to do so, subject to the following conditions:
62
+
63
+ The above copyright notice and this permission notice shall be included in
64
+ all copies or substantial portions of the Software.
65
+
66
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
67
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
68
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
69
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
70
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
71
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
72
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "wonderfl"
8
+ gem.summary = %Q{Ruby wrapper for the wonderfl API}
9
+ gem.description = %Q{#{gem.summary}. See README for more details.}
10
+ gem.email = "wellflat@gmail.com"
11
+ gem.homepage = "http://github.com/wellflat/wonderfl"
12
+ gem.authors = ["wellflat"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "webmock", ">= 1.3.3"
15
+ gem.add_dependency "json", ">= 1.2.4"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "wonderfl #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,81 @@
1
+ module Wonderfl
2
+ # The main client object through which the Wonderfl service may be accessed.
3
+ class Client
4
+ # api key
5
+ attr_accessor :api_key
6
+
7
+ # Requires api key, get yours from your account page
8
+ # (wonderfl.net/account/api_keys/create)
9
+ #
10
+ def initialize(api_key = nil)
11
+ @api_key = api_key
12
+ end
13
+
14
+ # Returns a Wonderfl::User object detailing the user information.
15
+ #
16
+ def get_user(user_name)
17
+ _validate?(user_name)
18
+ path = '/user/' + user_name
19
+ User.new(_request(path)[:body]['user'])
20
+ end
21
+
22
+ # Returns a Wonderfl::UserCodes object (Wonderfl::Code collection)
23
+ # detailing the recent 20 codes information posted by specified user.
24
+ #
25
+ def get_user_codes(user_name)
26
+ _validate?(user_name)
27
+ path = '/user/' + user_name + '/codes'
28
+ UserCodes.new(_request(path)[:body]['codes'])
29
+ end
30
+
31
+ # Returns a Wonderfl::Code object detailing the code information.
32
+ #
33
+ def get_code(code_id)
34
+ _validate?(code_id)
35
+ path = '/code/' + code_id
36
+ Code.new(_request(path)[:body]['code'], code_id)
37
+ end
38
+
39
+ # Returns a Wonderfl::CodeForks object (Wonderfl::Code collection)
40
+ # detailing the recent 50 codes information forked from specified code.
41
+ #
42
+ def get_code_forks(code_id)
43
+ _validate?(code_id)
44
+ path = '/code/' + code_id + '/forks'
45
+ CodeForks.new(_request(path)[:body]['forks'])
46
+ end
47
+
48
+ # Sends HTTP request and returns a parsed JSON response
49
+ #
50
+ private
51
+ def _request(path)
52
+ raise BadRequest, "api_key required" if @api_key.nil?
53
+ url = BASE_URL + path + '?api_key=' + @api_key
54
+ begin
55
+ response = Net::HTTP.get_response(URI.parse(url))
56
+ raise InternalServerError unless response.is_a? Net::HTTPOK
57
+ parsed = JSON.parse(response.body)
58
+ rescue JSON::ParserError => e
59
+ raise InternalServerError, 'JSON parse failed'
60
+ end
61
+ # dirty.. (cannot handle the HTTP Status Code)
62
+ # see also => http://wonderfl.net/apis/methods
63
+ if parsed['stat'].include? 'fail'
64
+ case parsed['message']
65
+ when 'invalid api key'
66
+ raise Unauthorized, "Request failed [#{parsed['message']}]"
67
+ when 'not found'
68
+ raise NotFound, "Request failed [#{parsed['message']}]"
69
+ end
70
+ end
71
+ { :code => response.code, :body => parsed }
72
+ end
73
+ # Returns true, if argument is a String
74
+ #
75
+ def _validate?(arg)
76
+ return true if arg.is_a? String
77
+ method_name = caller.first.scan(/`(.*)'/).to_s
78
+ raise BadRequest, 'String argument expected (' + method_name + ')'
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,54 @@
1
+ class Wonderfl::Code
2
+ include Wonderfl::Utils
3
+
4
+ attr_reader :thumbnail, :as3, :parent, :modified_date, :compile_ok,
5
+ :created_date, :forked_count, :license, :swf, :diff,
6
+ :user_icon, :user_name, :title, :id, :favorite_count
7
+
8
+ def initialize(payload, code_id = nil)
9
+ raise TypeError 'Hash argument expected' unless payload.is_a? Hash
10
+ @code_id = code_id
11
+ @compile_ok = payload['compile_ok'].to_i
12
+ @created_date = parse_time(payload['created_date'])
13
+ @id = payload['id']
14
+ @license = payload['license']
15
+ @parent = payload['parent']
16
+ @swf = payload['swf']
17
+ @thumbnail = payload['thumbnail']
18
+ @title = payload['title']
19
+ if code_id
20
+ @as3 = payload['as3']
21
+ @diff = payload['diff'].to_i
22
+ @favorite_count = payload['favorite_count'].to_i
23
+ @forked_count = payload['forked_count'].to_i
24
+ @modified_date = parse_time(payload['modified_date'])
25
+ end
26
+ if payload['user']
27
+ @user_icon = payload['user']['icon']
28
+ @user_name = payload['user']['name']
29
+ end
30
+ end
31
+
32
+ def to_s
33
+ if @code_id
34
+ <<-EOS
35
+ Wonderfl::Code {
36
+ thumbnail => #{@thumbnail}
37
+ parent => #{@parent}
38
+ modified_date => #{@modified_date}
39
+ compile_ok => #{@compile_ok}
40
+ created_date => #{@created_date}
41
+ forked_count => #{@forked_count}
42
+ license => #{@license}
43
+ swf => #{@swf}
44
+ diff => #{@diff}
45
+ user_icon => #{@user_icon}
46
+ user_name => #{@user_name}
47
+ title => #{@title}
48
+ id => #{@id}
49
+ favorite_count => #{@favorite_count}
50
+ }
51
+ EOS
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,17 @@
1
+ class Wonderfl::CodeForks
2
+ attr_reader :code_list
3
+
4
+ def initialize(payload)
5
+ raise TypeError, 'Array argument expected' unless payload.is_a? Array
6
+ @code_list = []
7
+ payload.each { |code| @code_list << Wonderfl::Code.new(code) }
8
+ end
9
+
10
+ def each
11
+ @code_list.each { |code| yield code }
12
+ end
13
+
14
+ def count
15
+ @code_list.length
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ class Wonderfl::User
2
+ attr_reader :icon, :external_url, :name, :description
3
+
4
+ def initialize(payload)
5
+ raise TypeError, 'Hash argument expected' unless payload.is_a? Hash
6
+ @icon = payload['icon']
7
+ @external_url = payload['external_url']
8
+ @name = payload['name']
9
+ @description = payload['description']
10
+ end
11
+
12
+ def to_s
13
+ <<-EOS
14
+ Wonderfl::User {
15
+ icon => #{@icon}
16
+ external_url => #{@external_url}
17
+ name => #{@name}
18
+ description => #{@description}
19
+ }
20
+ EOS
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ class Wonderfl::UserCodes
2
+ attr_reader :code_list
3
+
4
+ def initialize(payload)
5
+ raise TypeError, 'Array argument expected' unless payload.is_a? Array
6
+ @code_list = []
7
+ payload.each { |code| @code_list << Wonderfl::Code.new(code) }
8
+ end
9
+
10
+ def each
11
+ @code_list.each { |code| yield code }
12
+ end
13
+
14
+ def count
15
+ @code_list.length
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module Wonderfl::Utils
2
+ # Dumps object as a JSON string (for debugging).
3
+ #
4
+ def dump(path, api_key)
5
+ url = Wonderfl::BASE_URL + path + '?api_key=' + api_key
6
+ Net::HTTP.get_response(URI.parse(url)).body
7
+ end
8
+ # Creates a new Time object with the date from epoch.
9
+ #
10
+ def parse_time(date)
11
+ date ? Time.at(date) : nil
12
+ end
13
+ end
data/lib/wonderfl.rb ADDED
@@ -0,0 +1,25 @@
1
+ $:.unshift(File.dirname(__FILE__) + "/wonderfl/")
2
+
3
+ require 'net/http'
4
+ require 'time'
5
+ require 'rubygems'
6
+ require 'json'
7
+
8
+ Net::HTTP.version_1_2
9
+
10
+ module Wonderfl
11
+ VERSION = '0.0.1'
12
+ BASE_URL = 'http://api.wonderfl.net'
13
+ class BadRequest < StandardError; end
14
+ class Unauthorized < StandardError; end
15
+ class NotFound < StandardError; end
16
+ class InternalServerError < StandardError; end
17
+ end
18
+
19
+ require 'wonderfl/client'
20
+ require 'wonderfl/utils'
21
+ require 'wonderfl/user'
22
+ require 'wonderfl/user_codes'
23
+ require 'wonderfl/code'
24
+ require 'wonderfl/code_forks'
25
+
@@ -0,0 +1,24 @@
1
+ {
2
+ "code":
3
+ {
4
+ "thumbnail":"http://wonderfl.net/images/capture/0.jpg",
5
+ "as3":"...snip...",
6
+ "parent":null,
7
+ "modified_date":1254214438,
8
+ "compile_ok":"1",
9
+ "created_date":1254130273,
10
+ "forked_count":"0",
11
+ "license":"MIT",
12
+ "swf":"http://swf.wonderfl.net/swf/usercode/e.swf",
13
+ "diff":"0",
14
+ "user":
15
+ {
16
+ "icon":"http://wonderfl.net/images/icon/7",
17
+ "name":"mash"
18
+ },
19
+ "title":"flash on 2009-9-28",
20
+ "id":"ef31a1c226dd2acf60c14af9f99a6adefc87e26d",
21
+ "favorite_count":"0"
22
+ },
23
+ "stat":"ok"
24
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "forks":
3
+ [
4
+ {
5
+ "thumbnail":"http://wonderfl.net/img/common/noswf_100.gif",
6
+ "parent":"a0b5e4a3ee41798759e1bbacd65f06a1fe3be991",
7
+ "compile_ok":"0",
8
+ "user":
9
+ {
10
+ "icon":"http://wonderfl.net/img/common/img_user_anonymous.gif",
11
+ "name":"hacker_l95hn0cz"
12
+ },
13
+ "created_date":1252930621,
14
+ "id":"14ff1748980d4def239a847aba65ccd4ed8eae25",
15
+ "title":"forked from: wonderfl KeyVisual V.4.ja",
16
+ "license":"all",
17
+ "swf":"http://swf.wonderfl.net/swf/usercode/1/14/14ff/14ff1748980d4def239a847aba65ccd4ed8eae25.swf",
18
+ "diff":"1"
19
+ },
20
+ {
21
+ "thumbnail":"http://wonderfl.net/img/common/noswf_100.gif",
22
+ "parent":"a0b5e4a3ee41798759e1bbacd65f06a1fe3be991",
23
+ "compile_ok":"0",
24
+ "user":
25
+ {
26
+ "icon":"http://wonderfl.net/img/common/img_user_anonymous.gif",
27
+ "name":"hacker_l95hn0cz"
28
+ },
29
+ "created_date":1252930621,
30
+ "id":"14ff1748980d4def239a847aba65ccd4ed8eae25",
31
+ "title":"forked from: wonderfl KeyVisual V.4.ja",
32
+ "license":"all",
33
+ "swf":"http://swf.wonderfl.net/swf/usercode/1/14/14ff/14ff1748980d4def239a847aba65ccd4ed8eae25.swf",
34
+ "diff":"1"
35
+ }
36
+ ],
37
+ "stat":"ok"
38
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "user":
3
+ {
4
+ "icon":"http://wonderfl.net/images/icon/7",
5
+ "external_url":"http://maaash.jp/",
6
+ "name":"mash",
7
+ "description":"...snip..."
8
+ },
9
+ "stat":"ok"
10
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "codes":
3
+ [
4
+ {
5
+ "thumbnail":"http://wonderfl.net/images/capture/f/fb/fb97/fb973865de86ca120daf586670a4d7ad5f353ebe.jpg",
6
+ "parent":null,
7
+ "compile_ok":"1",
8
+ "id":"d6a0d0150fe63aaa6ae71fe827a0e0f201bd6041",
9
+ "created_date":1254214859,
10
+ "title":"flash on 2009-9-29",
11
+ "license":"other",
12
+ "swf":"http://swf.wonderfl.net/swf/usercode/d/d6/d6a0/d6a0d0150fe63aaa6ae71fe827a0e0f201bd6041.swf"
13
+ },
14
+ {
15
+ "thumbnail":"http://wonderfl.net/images/capture/0/0c/0c87/0c873d9dd5d1695ad9892cedd9ccbfc83a490494.jpg",
16
+ "parent":null,
17
+ "compile_ok":"1",
18
+ "id":"ef31a1c226dd2acf60c14af9f99a6adefc87e26d",
19
+ "created_date":1254130273,
20
+ "title":"flash on 2009-9-28",
21
+ "license":"MIT",
22
+ "swf":"http://swf.wonderfl.net/swf/usercode/e/ef/ef31/ef31a1c226dd2acf60c14af9f99a6adefc87e26d.swf"
23
+ }
24
+ ],
25
+ "stat":"ok"
26
+ }
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,12 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'wonderfl'
11
+ require 'webmock'
12
+ require 'json'
@@ -0,0 +1,163 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Wonderfl::Client do
4
+ before do
5
+ @client = Wonderfl::Client.new
6
+ @user_name = 'wellflat'
7
+ @api_key = 'foo'
8
+ @stub = WebMock.stub_request(:get, /http:\/\/api\.wonderfl\.net\/.*/)
9
+ end
10
+
11
+ describe 'when create new' do
12
+ it 'api_key should be nil' do
13
+ @client.api_key.should be_nil
14
+ end
15
+ end
16
+
17
+ describe 'when call get_user' do
18
+ before do
19
+ @client.api_key = @api_key
20
+ @response = File.open(File.dirname(__FILE__) + '/response/user')
21
+ end
22
+
23
+ it 'should return an instance of Wonderfl::User' do
24
+ @stub.to_return(:body => @response)
25
+ @client.get_user(@user_name).should be_an_instance_of Wonderfl::User
26
+ end
27
+
28
+ it 'should return detailing the user information' do
29
+ @stub.to_return(:body => @response)
30
+ user = @client.get_user(@user_name)
31
+ user.icon.should eql "http://wonderfl.net/images/icon/7"
32
+ user.external_url.should eql "http://maaash.jp/"
33
+ user.name.should eql "mash"
34
+ user.description.should eql "...snip..."
35
+ end
36
+
37
+ describe "#_validate?" do
38
+ it 'should raise error with invalid argument' do
39
+ lambda { @client.get_user(1.0) }.should raise_error Wonderfl::BadRequest
40
+ end
41
+ end
42
+
43
+ describe "#_request" do
44
+ it 'should raise error without set api_key' do
45
+ @client.api_key = nil
46
+ lambda { @client.get_user(@user_name) }.should raise_error Wonderfl::BadRequest
47
+ end
48
+
49
+ it 'should raise error with invalid api_key' do
50
+ @client.api_key = 'foo'
51
+ @stub.to_return(:body => '{"message":"invalid api key","stat":"fail"}')
52
+ lambda { @client.get_user(@user_name) }.should raise_error Wonderfl::Unauthorized
53
+ end
54
+
55
+ it 'should raise error with nonexistent user name' do
56
+ @stub.to_return(:body => '{"message":"not found","stat":"fail"}')
57
+ lambda { @client.get_user('foo_bar') }.should raise_error Wonderfl::NotFound
58
+ end
59
+
60
+ it 'should raise error cause internal server error' do
61
+ @stub.to_return(:status => 500)
62
+ lambda { @client.get_user(@user_name) }.should raise_error Wonderfl::InternalServerError
63
+ end
64
+ end
65
+ end
66
+
67
+ describe 'when call get_user_codes' do
68
+ before do
69
+ @client.api_key = @api_key
70
+ @stub.to_return(:body => File.open(File.dirname(__FILE__) + '/response/user_codes'))
71
+ end
72
+
73
+ it 'should return an instance of Wonderfl::UserCodes' do
74
+ @client.get_user_codes(@user_name).should be_an_instance_of Wonderfl::UserCodes
75
+ end
76
+
77
+ describe "Wonderfl::UserCodes#count" do
78
+ it 'should return a Numeric value' do
79
+ @client.get_user_codes(@user_name).count.should be_a_kind_of Numeric
80
+ end
81
+ end
82
+
83
+ describe "Wonderfl::UserCodes#each" do
84
+ it 'should yield an instance of Wonderfl::Code' do
85
+ codes = @client.get_user_codes(@user_name)
86
+ codes.each { |x| x.should be_an_instance_of Wonderfl::Code }
87
+ end
88
+ end
89
+
90
+ it 'should raise error with invalid argument' do
91
+ lambda { @client.get_user_codes(1.0) }.should raise_error Wonderfl::BadRequest
92
+ end
93
+ end
94
+
95
+ describe 'when call get_code' do
96
+ before do
97
+ @client.api_key = @api_key
98
+ @code_id = 'foo'
99
+ @stub.to_return(:body => File.open(File.dirname(__FILE__) + '/response/code'))
100
+ end
101
+
102
+ it 'should return an instance of Wonderfl::Code' do
103
+ @client.get_code(@code_id).should be_an_instance_of Wonderfl::Code
104
+ end
105
+
106
+ # be getting lazy...
107
+ it 'should return detailing the code information' do
108
+ code = @client.get_code(@code_id)
109
+ code.thumbnail.should eql "http://wonderfl.net/images/capture/0.jpg"
110
+ code.as3.should eql "...snip..."
111
+ code.parent.should be_nil
112
+ code.modified_date.should be_a_kind_of Time
113
+ code.compile_ok.should be_a_kind_of Numeric
114
+ code.compile_ok.should eql 1
115
+ code.created_date.should be_a_kind_of Time
116
+ code.forked_count.should be_a_kind_of Numeric
117
+ code.forked_count.should eql 0
118
+ code.license.should eql "MIT"
119
+ code.swf.should eql "http://swf.wonderfl.net/swf/usercode/e.swf"
120
+ code.diff.should be_a_kind_of Numeric
121
+ code.diff.should eql 0
122
+ code.user_icon.should eql "http://wonderfl.net/images/icon/7"
123
+ code.user_name.should eql "mash"
124
+ code.title.should eql "flash on 2009-9-28"
125
+ code.id.should eql "ef31a1c226dd2acf60c14af9f99a6adefc87e26d"
126
+ code.favorite_count.should be_a_kind_of Numeric
127
+ code.favorite_count.should eql 0
128
+ end
129
+
130
+ it 'should raise error with invalid argument' do
131
+ lambda { @client.get_code(1.0) }.should raise_error Wonderfl::BadRequest
132
+ end
133
+ end
134
+
135
+ describe 'when call get code_forks' do
136
+ before do
137
+ @client.api_key = @api_key
138
+ @code_id = 'bar'
139
+ @stub.to_return(:body => File.open(File.dirname(__FILE__) + '/response/code_forks'))
140
+ end
141
+
142
+ it 'should return an instance of Wonderfl::CodeForks' do
143
+ @client.get_code_forks(@code_id).should be_an_instance_of Wonderfl::CodeForks
144
+ end
145
+
146
+ describe "Wonderfl::CodeForks#count" do
147
+ it 'should return a Numeric value' do
148
+ @client.get_code_forks(@code_id).count.should be_a_kind_of Numeric
149
+ end
150
+ end
151
+
152
+ describe "Wonderfl::CodeForks#each" do
153
+ it 'should yield an instance of Wonderfl::Code' do
154
+ codes = @client.get_code_forks(@code_id)
155
+ codes.each { |x| x.should be_an_instance_of Wonderfl::Code }
156
+ end
157
+ end
158
+
159
+ it 'should raise error with invalid argument' do
160
+ lambda { @client.get_code_forks(1.0) }.should raise_error Wonderfl::BadRequest
161
+ end
162
+ end
163
+ end
data/wonderfl.gemspec ADDED
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{wonderfl}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["wellflat"]
12
+ s.date = %q{2010-08-16}
13
+ s.description = %q{Ruby wrapper for the wonderfl API. See README for more details.}
14
+ s.email = %q{wellflat@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/wonderfl.rb",
27
+ "lib/wonderfl/client.rb",
28
+ "lib/wonderfl/code.rb",
29
+ "lib/wonderfl/code_forks.rb",
30
+ "lib/wonderfl/user.rb",
31
+ "lib/wonderfl/user_codes.rb",
32
+ "lib/wonderfl/utils.rb",
33
+ "spec/response/code",
34
+ "spec/response/code_forks",
35
+ "spec/response/user",
36
+ "spec/response/user_codes",
37
+ "spec/spec.opts",
38
+ "spec/spec_helper.rb",
39
+ "spec/wonderfl_spec.rb",
40
+ "wonderfl.gemspec"
41
+ ]
42
+ s.homepage = %q{http://github.com/wellflat/wonderfl}
43
+ s.rdoc_options = ["--charset=UTF-8"]
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = %q{1.3.6}
46
+ s.summary = %q{Ruby wrapper for the wonderfl API}
47
+ s.test_files = [
48
+ "spec/spec_helper.rb",
49
+ "spec/wonderfl_spec.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
58
+ s.add_development_dependency(%q<webmock>, [">= 1.3.3"])
59
+ s.add_runtime_dependency(%q<json>, [">= 1.2.4"])
60
+ else
61
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
62
+ s.add_dependency(%q<webmock>, [">= 1.3.3"])
63
+ s.add_dependency(%q<json>, [">= 1.2.4"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
67
+ s.add_dependency(%q<webmock>, [">= 1.3.3"])
68
+ s.add_dependency(%q<json>, [">= 1.2.4"])
69
+ end
70
+ end
71
+
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wonderfl
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - wellflat
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-16 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: webmock
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 3
44
+ - 3
45
+ version: 1.3.3
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: json
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 2
58
+ - 4
59
+ version: 1.2.4
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ description: Ruby wrapper for the wonderfl API. See README for more details.
63
+ email: wellflat@gmail.com
64
+ executables: []
65
+
66
+ extensions: []
67
+
68
+ extra_rdoc_files:
69
+ - LICENSE
70
+ - README.rdoc
71
+ files:
72
+ - .document
73
+ - .gitignore
74
+ - LICENSE
75
+ - README.rdoc
76
+ - Rakefile
77
+ - VERSION
78
+ - lib/wonderfl.rb
79
+ - lib/wonderfl/client.rb
80
+ - lib/wonderfl/code.rb
81
+ - lib/wonderfl/code_forks.rb
82
+ - lib/wonderfl/user.rb
83
+ - lib/wonderfl/user_codes.rb
84
+ - lib/wonderfl/utils.rb
85
+ - spec/response/code
86
+ - spec/response/code_forks
87
+ - spec/response/user
88
+ - spec/response/user_codes
89
+ - spec/spec.opts
90
+ - spec/spec_helper.rb
91
+ - spec/wonderfl_spec.rb
92
+ - wonderfl.gemspec
93
+ has_rdoc: true
94
+ homepage: http://github.com/wellflat/wonderfl
95
+ licenses: []
96
+
97
+ post_install_message:
98
+ rdoc_options:
99
+ - --charset=UTF-8
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ requirements: []
117
+
118
+ rubyforge_project:
119
+ rubygems_version: 1.3.6
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Ruby wrapper for the wonderfl API
123
+ test_files:
124
+ - spec/spec_helper.rb
125
+ - spec/wonderfl_spec.rb