dropio 0.9.1 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,3 +1,15 @@
1
+ === 1.0.0 / 2009-10-02
2
+
3
+ * Moved to API version 2.0
4
+
5
+ === 0.9.6 / 2009-10-01
6
+
7
+ * Removed original file attribute from gem.
8
+
9
+ === 0.9.5 / 2009-09-09
10
+
11
+ * Move gem to github.
12
+
1
13
  === 0.9.0 / 2008-11-10
2
14
 
3
15
  * First gem release.
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 Drop.io, Inc.
1
+ Copyright (c) 2009 Drop.io, Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/Manifest CHANGED
@@ -1,21 +1,22 @@
1
1
  History.rdoc
2
+ lib/dropio/api.rb
2
3
  lib/dropio/asset.rb
3
- lib/dropio/client/mapper.rb
4
- lib/dropio/client/multipart_post.rb
5
4
  lib/dropio/client.rb
6
5
  lib/dropio/comment.rb
7
6
  lib/dropio/drop.rb
8
7
  lib/dropio/resource.rb
8
+ lib/dropio/subscription.rb
9
9
  lib/dropio.rb
10
10
  LICENSE.txt
11
11
  Manifest
12
12
  Rakefile
13
13
  Readme.rdoc
14
+ spec/dropio/api_spec.rb
14
15
  spec/dropio/asset_spec.rb
15
- spec/dropio/client/mapper_spec.rb
16
16
  spec/dropio/client_spec.rb
17
17
  spec/dropio/comment_spec.rb
18
18
  spec/dropio/drop_spec.rb
19
+ spec/dropio/subscription_spec.rb
19
20
  spec/dropio_spec.rb
20
21
  spec/spec.opts
21
22
  spec/spec_helper.rb
data/Rakefile CHANGED
@@ -7,9 +7,9 @@ begin
7
7
 
8
8
  Echoe.new('dropio', Dropio::VERSION) do |echoe|
9
9
  echoe.summary = "A Ruby client library for the Drop.io API (http://api.drop.io)"
10
- echoe.author = ["Jake Good", "Peter Jaros"]
11
- echoe.email = ["jake@dropio.com", "peeja@dropio.com"]
12
- echoe.url = "http://github.com/whoisjake/dropio_api_ruby"
10
+ echoe.author = ["Jake Good"]
11
+ echoe.email = ["jake@dropio.com"]
12
+ echoe.url = "http://github.com/dropio/dropio"
13
13
  echoe.changelog = "History.rdoc"
14
14
  echoe.ignore_pattern = "tmtags"
15
15
  echoe.runtime_dependencies = ["mime-types", "json"]
data/Readme.rdoc CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Before using the Dropio library, the application must set an API key. This key will be used for all requests to the server. To get an API key, go to http://api.drop.io. Then make sure you set the API key before you use the API:
6
6
 
7
- Dropio.api_key = "83a05513ddddb73e75c9d8146c115f7fd8e90de6"
7
+ Dropio::Config.api_key = "83a05513ddddb73e75c9d8146c115f7fd8e90de6"
8
8
 
9
9
 
10
10
  == The Drop object
data/dropio.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{dropio}
5
- s.version = "0.9.1"
5
+ s.version = "1.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Jake Good, Peter Jaros"]
9
- s.date = %q{2008-11-11}
10
- s.description = %q{A Ruby client library for the Drop.io API (http://api.drop.io)}
11
- s.email = ["jake@dropio.com", "peeja@dropio.com"]
8
+ s.authors = ["Jake Good"]
9
+ s.date = %q{2009-09-09}
10
+ s.description = %q{A Ruby client library for the Drop.io API (http://api.drop.io). Please email jake@dropio.com with any questions.}
11
+ s.email = ["jake@dropio.com"]
12
12
  s.extra_rdoc_files = ["History.rdoc", "Readme.rdoc", "Todo.rdoc"]
13
- s.files = ["History.rdoc", "lib/dropio/asset.rb", "lib/dropio/client/mapper.rb", "lib/dropio/client/multipart_post.rb", "lib/dropio/client.rb", "lib/dropio/comment.rb", "lib/dropio/drop.rb", "lib/dropio/resource.rb", "lib/dropio.rb", "LICENSE.txt", "Manifest", "Rakefile", "Readme.rdoc", "spec/dropio/asset_spec.rb", "spec/dropio/client/mapper_spec.rb", "spec/dropio/client_spec.rb", "spec/dropio/comment_spec.rb", "spec/dropio/drop_spec.rb", "spec/dropio_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "Todo.rdoc", "dropio.gemspec"]
13
+ s.files = ["History.rdoc", "lib/dropio/api.rb", "lib/dropio/asset.rb", "lib/dropio/client.rb", "lib/dropio/comment.rb", "lib/dropio/drop.rb", "lib/dropio/resource.rb", "lib/dropio/subscription.rb","lib/dropio.rb", "LICENSE.txt", "Manifest", "Rakefile", "Readme.rdoc", "spec/dropio/api_spec.rb", "spec/dropio/asset_spec.rb", "spec/dropio/client_spec.rb", "spec/dropio/comment_spec.rb", "spec/dropio/drop_spec.rb","spec/dropio/subscription_spec.rb", "spec/dropio_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "Todo.rdoc", "dropio.gemspec"]
14
14
  s.has_rdoc = true
15
- s.homepage = %q{http://github.com/whoisjake/dropio_api_ruby}
15
+ s.homepage = %q{http://github.com/dropio/dropio}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Dropio", "--main", "Readme.rdoc"]
17
17
  s.require_paths = ["lib"]
18
18
  s.rubyforge_project = %q{dropio}
@@ -25,16 +25,19 @@ Gem::Specification.new do |s|
25
25
 
26
26
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
27
  s.add_runtime_dependency(%q<mime-types>, [">= 0"])
28
- s.add_runtime_dependency(%q<json>, [">= 0"])
28
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
29
+ s.add_runtime_dependency(%q<multipart-post>,[">= 0"])
29
30
  s.add_development_dependency(%q<echoe>, [">= 0"])
30
31
  else
31
32
  s.add_dependency(%q<mime-types>, [">= 0"])
32
- s.add_dependency(%q<json>, [">= 0"])
33
+ s.add_dependency(%q<httparty>, [">= 0"])
34
+ s.add_dependency(%q<multipart-post>, [">= 0"])
33
35
  s.add_dependency(%q<echoe>, [">= 0"])
34
36
  end
35
37
  else
36
38
  s.add_dependency(%q<mime-types>, [">= 0"])
37
- s.add_dependency(%q<json>, [">= 0"])
39
+ s.add_dependency(%q<httparty>, [">= 0"])
40
+ s.add_dependency(%q<multipart-post>, [">= 0"])
38
41
  s.add_dependency(%q<echoe>, [">= 0"])
39
42
  end
40
43
  end
data/lib/dropio/api.rb ADDED
@@ -0,0 +1,169 @@
1
+ require 'rbconfig'
2
+
3
+ class Dropio::Api
4
+ include HTTParty
5
+ format :json
6
+
7
+ RUBY_VERSION = %w{MAJOR MINOR TEENY}.map { |k| Config::CONFIG[k] }.join(".")
8
+ USER_AGENT_STRING = "DropioAPI-Ruby/#{Dropio::VERSION} (Ruby #{RUBY_VERSION} #{Config::CONFIG["host"]}; +http://github.com/dropio/dropio/tree/)"
9
+ headers 'Accept' => 'application/json', 'User-Agent' => USER_AGENT_STRING
10
+
11
+ def initialize
12
+ self.class.default_params :api_key => Dropio::Config.api_key, :version => Dropio::Config.version, :format => "json"
13
+ self.class.base_uri Dropio::Config.api_url
14
+ end
15
+
16
+ def drop(drop_name, token = nil)
17
+ self.class.get("/drops/#{drop_name}", :query => {:token => token})
18
+ end
19
+
20
+ def generate_drop_url(drop_name, token)
21
+ signed_url(drop_name,token)
22
+ end
23
+
24
+ def create_drop(params = {})
25
+ self.class.post("/drops",:body => params)
26
+ end
27
+
28
+ def update_drop(drop_name, admin_token, params = {})
29
+ params[:token] = admin_token
30
+ self.class.put("/drops/#{drop_name}", :body => params)
31
+ end
32
+
33
+ def empty_drop(drop_name, admin_token)
34
+ self.class.put("/drops/#{drop_name}/empty", :query => {:token => admin_token})
35
+ end
36
+
37
+ def delete_drop(drop_name, admin_token)
38
+ self.class.delete("/drops/#{drop_name}", :query => {:token => admin_token})
39
+ end
40
+
41
+ def promote_nick(drop_name, nick, admin_token)
42
+ self.class.post("/drops/#{drop_name}", :query => {:nick => nick, :token => admin_token})
43
+ end
44
+
45
+ def drop_upload_code(drop_name, token = nil)
46
+ self.class.get("/drops/#{drop_name}/upload_code", :query => {:token => token})
47
+ end
48
+
49
+ def create_link(drop_name, url, title = nil, description = nil, token = nil)
50
+ self.class.post("/drops/#{drop_name}/assets", :body => {:url => url, :title => title, :description => description, :token => token})
51
+ end
52
+
53
+ def create_note(drop_name, contents, title = nil, token = nil)
54
+ params = {:contents => contents, :title => title, :token => token}
55
+ self.class.post("/drops/#{drop_name}/assets", :body => params)
56
+ end
57
+
58
+ def add_file(drop_name, file_path, comment = nil, token = nil)
59
+ url = URI.parse("http://assets.drop.io/upload/")
60
+ r = nil
61
+ File.open(file_path) do |file|
62
+ mime_type = (MIME::Types.type_for(file_path)[0] || MIME::Types["application/octet-stream"][0])
63
+ req = Net::HTTP::Post::Multipart.new url.path,
64
+ { 'api_key' => self.class.default_params[:api_key], 'drop_name' => drop_name, 'format' => 'json',
65
+ 'token' => token, 'version' => '2.0', 'comment' => comment, 'file' => UploadIO.new(file, mime_type, file_path) }
66
+ http = Net::HTTP.new(url.host, url.port)
67
+ r = http.start{|http| http.request(req)}
68
+ end
69
+
70
+ (r.nil? or r.body.nil? or r.body.empty?) ? [] : HTTParty::Response.new(Crack::JSON.parse(r.body), r.body, r.code, r.message, r.to_hash)
71
+ end
72
+
73
+ def add_file_from_url(drop_name, url, token = nil)
74
+ self.class.post("/drops/#{drop_name}/assets", :body => {:token => token, :file_url => url})
75
+ end
76
+
77
+ def assets(drop_name, page = 1, order = :oldest, token = nil)
78
+ self.class.get("/drops/#{drop_name}/assets", :query => {:token => token, :page => page, :order => order.to_s})
79
+ end
80
+
81
+ def asset(drop_name, asset_name, token = nil)
82
+ self.class.get("/drops/#{drop_name}/assets/#{asset_name}", :query => {:token => token})
83
+ end
84
+
85
+ def generate_asset_url(drop_name, asset_name, token)
86
+ signed_url(drop_name, token, asset_name)
87
+ end
88
+
89
+ def asset_embed_code(drop_name, asset_name, token = nil)
90
+ self.class.get("/drops/#{drop_name}/assets/#{asset_name}/embed_code", :query => {:token => token})
91
+ end
92
+
93
+ def update_asset(drop_name, asset_name, params = {}, token = nil)
94
+ params[:token] = token
95
+ self.class.put("/drops/#{drop_name}/assets/#{asset_name}", :body => params)
96
+ end
97
+
98
+ def delete_asset(drop_name, asset_name, token = nil)
99
+ self.class.delete("/drops/#{drop_name}/assets/#{asset_name}", :body => {:token => token})
100
+ end
101
+
102
+ def send_asset_to_drop(drop_name, asset_name, target_drop, drop_token = nil, token = nil)
103
+ self.class.post("/drops/#{drop_name}/assets/#{asset_name}/send_to", :body => {:medium => "drop", :drop_name => target_drop, :token => token, :drop_token => drop_token})
104
+ end
105
+
106
+ def send_asset_to_fax(drop_name, asset_name, fax_number, token = nil)
107
+ self.class.post("/drops/#{drop_name}/assets/#{asset_name}/send_to", :body => {:medium => "fax", :fax_number => fax_number, :token => token})
108
+ end
109
+
110
+ def send_asset_to_emails(drop_name, asset_name, emails, message = nil, token = nil)
111
+ self.class.post("/drops/#{drop_name}/assets/#{asset_name}/send_to", :body => {:medium => "emails", :emails => emails, message => message, :token => token})
112
+ end
113
+
114
+ def copy_asset(drop_name, asset_name, target_drop, target_drop_token, token = nil)
115
+ params = {:token => token, :drop_name => target_drop, :drop_token => target_drop_token}
116
+ self.class.post("/drops/#{drop_name}/assets/#{asset_name}/copy", :body => params)
117
+ end
118
+
119
+ def move_asset(drop_name, asset_name, target_drop, target_drop_token, token = nil)
120
+ params = {:token => token, :drop_name => target_drop, :drop_token => target_drop_token}
121
+ self.class.post("/drops/#{drop_name}/assets/#{asset_name}/move", :body => params)
122
+ end
123
+
124
+ def comments(drop_name, asset_name, token = nil)
125
+ self.class.get("/drops/#{drop_name}/assets/#{asset_name}/comments", :query => {:token => token})
126
+ end
127
+
128
+ def create_comment(drop_name, asset_name, contents, token = nil)
129
+ self.class.post("/drops/#{drop_name}/assets/#{asset_name}/comments",:body => {:contents => contents, :token => token})
130
+ end
131
+
132
+ def comment(drop_name, asset_name, comment_id, token = nil)
133
+ self.class.get("/drops/#{drop_name}/assets/#{asset_name}/comments/#{comment_id}", :query => {:token => token})
134
+ end
135
+
136
+ def update_comment(drop_name, asset_name, comment_id, contents, admin_token)
137
+ self.class.put("/drops/#{drop_name}/assets/#{asset_name}/comments/#{comment_id}", :body => {:contents => contents, :token => admin_token})
138
+ end
139
+
140
+ def delete_comment(drop_name, asset_name, comment_id, admin_token)
141
+ self.class.delete("/drops/#{drop_name}/assets/#{asset_name}/comments/#{comment_id}", :body => {:token => admin_token})
142
+ end
143
+
144
+ def create_twitter_subscription(drop_name, username, password, message = nil, events = {}, token = nil)
145
+ self.class.post("/drops/#{drop_name}/subscriptions", :body => { :token => token, :type => "twitter", :username => username, :password => password, :message => message}.merge(events))
146
+ end
147
+
148
+ def create_email_subscription(drop_name, emails, welcome_message = nil, welcome_subject = nil, welcome_from = nil, message = nil, events = {}, token = nil)
149
+ params = {:token => token, :type => "email", :emails => emails, :welcome_from => welcome_from , :welcome_subject => welcome_subject, :welcome_message => welcome_message }.merge(events)
150
+ self.class.post("/drops/#{drop_name}/subscriptions", :body => params)
151
+ end
152
+
153
+ def subscriptions(drop_name, admin_token)
154
+ self.class.get("/drops/#{drop_name}/subscriptions", :query => {:token => admin_token})
155
+ end
156
+
157
+
158
+ private
159
+
160
+ def signed_url(drop_name, token, asset_name = nil)
161
+ # 10 minute window.
162
+ expires = (Time.now.utc + 10*60).to_i
163
+ path = Dropio::Config.base_url + "/#{drop_name}"
164
+ path += "/asset/#{asset_name}" if asset_name
165
+ path += "/from_api"
166
+ sig = Digest::SHA1.hexdigest("#{expires}+#{token}+#{drop_name}")
167
+ path + "?expires=#{expires}&signature=#{sig}"
168
+ end
169
+ end
data/lib/dropio/asset.rb CHANGED
@@ -1,60 +1,80 @@
1
1
  class Dropio::Asset < Dropio::Resource
2
2
 
3
3
  attr_accessor :drop, :name, :type, :title, :description, :filesize, :created_at,
4
- :thumbnail, :status, :file, :converted, :hidden_url, :pages,
4
+ :thumbnail, :status, :converted, :hidden_url, :pages, :fax_status,
5
5
  :duration, :artist, :track_title, :height, :width, :contents, :url
6
+
7
+ # Finds a particular Asset by drop and asset name.
8
+ def self.find(drop, name)
9
+ Dropio::Resource.client.asset(drop,name)
10
+ end
6
11
 
7
- # Returns the comments on this asset. Comments are loaded lazily. The first
12
+ # Returns the comments on this Asset. Comments are loaded lazily. The first
8
13
  # call to +comments+ will fetch the comments from the server. They are then
9
- # cached until the asset is reloaded.
14
+ # cached until the Asset is reloaded.
10
15
  def comments
11
- @comments = Dropio::Client.instance.find_comments(self) if @comments.nil?
16
+ @comments = Dropio::Resource.client.comments(self) if @comments.nil?
12
17
  @comments ||= []
13
- end
18
+ end
14
19
 
15
- # Adds a comment to the asset with the given +contents+. Returns the
20
+ # Gets the Assets's embed code
21
+ def embed_code
22
+ Dropio::Resource.client.asset_embed_code(self)
23
+ end
24
+
25
+ # Adds a comment to the Asset with the given +contents+. Returns the
16
26
  # new +Comment+.
17
27
  def create_comment(contents)
18
- Dropio::Client.instance.create_comment(self, contents)
28
+ Dropio::Resource.client.create_comment(self, contents)
19
29
  end
20
30
 
21
- # Saves the asset back to drop.io.
31
+ # Saves the Asset back to drop.io.
22
32
  def save
23
- Dropio::Client.instance.save_asset(self)
33
+ Dropio::Resource.client.update_asset(self)
24
34
  end
25
35
 
26
- # Destroys the asset on drop.io. Don't try to use an Asset after destroying it.
36
+ # Destroys the Asset on drop.io. Don't try to use an Asset after destroying it.
27
37
  def destroy!
28
- Dropio::Client.instance.destroy_asset(self)
38
+ Dropio::Resource.client.delete_asset(self)
29
39
  nil
30
40
  end
31
41
 
42
+ # Copies the Asset to the given drop. The +token+ is the target drop's token if required to add files.
43
+ def copy_to(target_drop)
44
+ Dropio::Resource.client.copy_asset(self, target_drop)
45
+ end
46
+
47
+ # Moves the Asset to the given drop. The +token+ is the target drop's token if required to add files.
48
+ def move_to(target_drop)
49
+ Dropio::Resource.client.move_asset(self, target_drop)
50
+ end
51
+
32
52
  # Returns true if the Asset can be faxed.
33
53
  def faxable?
34
- return type == "Document"
54
+ return type.downcase == "document"
35
55
  end
36
56
 
37
- # Fax the asset to the given +fax_number+. Make sure the Asset is +faxable?+
57
+ # Fax the Asset to the given +fax_number+. Make sure the Asset is +faxable?+
38
58
  # first, or +send_to_fax+ will raise an error.
39
59
  def send_to_fax(fax_number)
40
60
  raise "Can't fax Asset: #{self.inspect} is not faxable" unless faxable?
41
- Dropio::Client.instance.send_to_fax(self, fax_number)
61
+ Dropio::Resource.client.send_asset_to_fax(self, fax_number)
42
62
  nil
43
63
  end
44
64
 
45
- # Sends the asset to the given +emails+ with an optional +message+.
65
+ # Sends the Asset to the given +emails+ with an optional +message+.
46
66
  def send_to_emails(emails = [], message = nil)
47
- Dropio::Client.instance.send_to_emails(self, emails, message)
67
+ Dropio::Resource.client.send_asset_to_emails(self, emails, message)
48
68
  end
49
69
 
50
- # Sends the asset to a Drop by +drop_name+
51
- def send_to_drop(drop_name)
52
- Dropio::Client.instance.send_to_drop(self, drop_name)
70
+ # Sends the Asset to a Drop by +drop_name+
71
+ def send_to_drop(drop)
72
+ Dropio::Resource.client.send_asset_to_drop(self, drop)
53
73
  end
54
74
 
55
75
  # Generates an authenticated URL that will bypass any login action.
56
76
  def generate_url
57
- Dropio::Client.instance.generate_asset_url(self)
77
+ Dropio::Resource.client.generate_asset_url(self)
58
78
  end
59
79
 
60
80
  end