dropmark 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +139 -0
- data/Rakefile +1 -0
- data/dropmark.gemspec +24 -0
- data/lib/dropmark.rb +48 -0
- data/lib/dropmark/authentication.rb +21 -0
- data/lib/dropmark/collection.rb +27 -0
- data/lib/dropmark/comment.rb +19 -0
- data/lib/dropmark/error.rb +32 -0
- data/lib/dropmark/file.rb +12 -0
- data/lib/dropmark/item.rb +30 -0
- data/lib/dropmark/user.rb +39 -0
- data/lib/dropmark/version.rb +3 -0
- metadata +92 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Oak Studios LLC
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
Dropmark Gem
|
2
|
+
============
|
3
|
+
|
4
|
+
- [Installation](#installation)
|
5
|
+
- [Using this gem in your application](#using-this-gem-in-your-application)
|
6
|
+
- [Using the API](#using-the-api)
|
7
|
+
- [Contributing](#contributing)
|
8
|
+
|
9
|
+
Installation
|
10
|
+
------------
|
11
|
+
|
12
|
+
The Dropmark gem is available for installation on [Rubygems](https://rubygems.org/gems/dropmark). To install run:
|
13
|
+
|
14
|
+
gem install dropmark # todo
|
15
|
+
|
16
|
+
|
17
|
+
Using this gem in your application
|
18
|
+
----------------------------------
|
19
|
+
|
20
|
+
To use this gem in your application, add the following to your Gemfile:
|
21
|
+
|
22
|
+
gem 'dropmark', :git => 'git://github.com/dropmark/dropmark-gem.git'
|
23
|
+
|
24
|
+
|
25
|
+
Using the API
|
26
|
+
-------------
|
27
|
+
|
28
|
+
This gem allows you to interact with the Dropmark API.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'dropmark'
|
32
|
+
|
33
|
+
# authenticate application
|
34
|
+
Dropmark.configure do |config|
|
35
|
+
config.api_key = 'API_KEY'
|
36
|
+
config.api_base = 'https://api.dropmark.com/v1' # optional
|
37
|
+
config.user_id = 'USER_ID' # optional, see below to retrieve
|
38
|
+
config.user_token = 'USER_TOKEN' # optional, see below to retrieve
|
39
|
+
end
|
40
|
+
|
41
|
+
# retreive user token if needed
|
42
|
+
user = Dropmark::User.auth(email: 'EMAIL', password: 'PASSWORD')
|
43
|
+
# note: store user.id and user.token for future use, never store password
|
44
|
+
|
45
|
+
# get authenticated user
|
46
|
+
user = Dropmark::User.find('me')
|
47
|
+
|
48
|
+
# get first 20 collections for authenticated user
|
49
|
+
collections = Dropmark::Collection.all(page: 1, count: 20)
|
50
|
+
|
51
|
+
# get collection by id
|
52
|
+
collection = Dropmark::Collection.find(133727)
|
53
|
+
|
54
|
+
# create new collection for authenticated user
|
55
|
+
collection = Dropmark::Collection.create(
|
56
|
+
name: 'New collection',
|
57
|
+
type: 'private', # optional ('private', 'public', 'global')
|
58
|
+
sort_by: 'created_at', # optional ('name', 'created_at', 'updated_at')
|
59
|
+
sort_order: 'desc', # optional ('asc', 'desc')
|
60
|
+
thumbnails: 'square', # optional ('square', 'full')
|
61
|
+
labels: 'true', # optional ('true', 'false')
|
62
|
+
)
|
63
|
+
|
64
|
+
# delete collection
|
65
|
+
collection.destroy
|
66
|
+
# or delete collection by id
|
67
|
+
Dropmark::Collection.destroy_existing(133727)
|
68
|
+
|
69
|
+
# sort collections by ids
|
70
|
+
collections = Dropmark::Collection.sort([101, 102, 103])
|
71
|
+
|
72
|
+
# get items in collection
|
73
|
+
items = collection.items
|
74
|
+
# or get items without fetching collection
|
75
|
+
items = Dropmark::Item.where(collection_id: 133727)
|
76
|
+
|
77
|
+
# get item by id
|
78
|
+
item = Dropmark::Item.find(2139403)
|
79
|
+
|
80
|
+
# sort items in collection by item ids
|
81
|
+
items = collection.sort_items([101, 102, 103])
|
82
|
+
# or sort items without fetching collection
|
83
|
+
items = Dropmark::Item.sort(collection_id, [101, 102, 103])
|
84
|
+
|
85
|
+
# create new item
|
86
|
+
item = collection.items.create(content: 'http://dropmark.com')
|
87
|
+
# or
|
88
|
+
item = Dropmark::Item.create(
|
89
|
+
collection_id: 133727,
|
90
|
+
name: 'Logo', # optional
|
91
|
+
content: 'http://dropmark.com/assets/images/logo.png', # required (URL, file, or text)
|
92
|
+
description: 'Dropmark logo', # optional
|
93
|
+
link: 'http://dropmark.com', # optional
|
94
|
+
thumbnail: 'http://dropmark.com/assets/images/logo.png', # optional
|
95
|
+
shareable: 'true' # optional
|
96
|
+
)
|
97
|
+
|
98
|
+
# upload file item
|
99
|
+
item = Dropmark::Item.create(
|
100
|
+
collection_id: 133727,
|
101
|
+
content: Dropmark::File.new('~/photo.jpg')
|
102
|
+
)
|
103
|
+
|
104
|
+
# update item
|
105
|
+
item.name = 'My Photo'
|
106
|
+
item.save
|
107
|
+
# or update by id
|
108
|
+
item = Dropmark::Item.save_existing(2316519, name: 'My Photo')
|
109
|
+
|
110
|
+
# delete item
|
111
|
+
item.destroy
|
112
|
+
# or delete by id
|
113
|
+
Dropmark::Item.destroy_existing(2139403)
|
114
|
+
|
115
|
+
# get item comments
|
116
|
+
comments = item.comments.all
|
117
|
+
|
118
|
+
# add comment
|
119
|
+
comment = item.comments.create(body: 'My comment')
|
120
|
+
# or comment by item id
|
121
|
+
comment = Dropmark::Comment.create(item_id: 2316545, body: 'My comment')
|
122
|
+
|
123
|
+
# delete comment
|
124
|
+
comment.destroy
|
125
|
+
# or comment by id
|
126
|
+
Dropmark::Comment.destroy_existing(2139403)
|
127
|
+
```
|
128
|
+
|
129
|
+
|
130
|
+
Contributing
|
131
|
+
------------
|
132
|
+
|
133
|
+
Help us improve this gem:
|
134
|
+
|
135
|
+
1. Fork it
|
136
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
137
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
138
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
139
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/dropmark.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dropmark/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "dropmark"
|
8
|
+
gem.version = Dropmark::VERSION
|
9
|
+
gem.authors = ["dropmark"]
|
10
|
+
gem.email = ["api@dropmark.com"]
|
11
|
+
gem.description = %q{A Ruby interface and command line utility for the Dropmark API.}
|
12
|
+
gem.summary = "Dropmark Ruby interface"
|
13
|
+
gem.homepage = "http://dropmark.com"
|
14
|
+
|
15
|
+
gem.required_ruby_version = '>= 1.8'
|
16
|
+
|
17
|
+
gem.add_runtime_dependency 'her'
|
18
|
+
gem.add_runtime_dependency 'mime-types'
|
19
|
+
|
20
|
+
gem.files = `git ls-files`.split($/)
|
21
|
+
gem.files += Dir.glob("lib/**/*.rb")
|
22
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
23
|
+
gem.require_paths = ["lib"]
|
24
|
+
end
|
data/lib/dropmark.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
libdir = File.dirname(__FILE__)
|
2
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
3
|
+
|
4
|
+
require 'her'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'rbconfig'
|
7
|
+
require 'dropmark/version'
|
8
|
+
require 'dropmark/authentication'
|
9
|
+
require 'dropmark/error'
|
10
|
+
require 'dropmark/file'
|
11
|
+
|
12
|
+
module Dropmark
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_accessor :api_key, :api_base, :user_id, :user_token
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.api
|
19
|
+
@api
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.configure(&blk)
|
23
|
+
options = OpenStruct.new
|
24
|
+
yield(options)
|
25
|
+
|
26
|
+
@api_key = options.try(:api_key)
|
27
|
+
@api_base = options.try(:api_base) || 'https://api.dropmark.com/v1'
|
28
|
+
@user_id = options.try(:user_id)
|
29
|
+
@user_token = options.try(:user_token)
|
30
|
+
|
31
|
+
@api = Her::API.new
|
32
|
+
@api.setup :url => @api_base do |c|
|
33
|
+
c.use Faraday::Response::Logger
|
34
|
+
c.use Dropmark::Authentication
|
35
|
+
c.use Faraday::Request::Multipart
|
36
|
+
c.use Faraday::Request::UrlEncoded
|
37
|
+
c.use Her::Middleware::DefaultParseJSON
|
38
|
+
c.use Faraday::Adapter::NetHttp
|
39
|
+
c.use Dropmark::Error::RaiseError
|
40
|
+
end
|
41
|
+
require 'dropmark/collection'
|
42
|
+
require 'dropmark/comment'
|
43
|
+
require 'dropmark/item'
|
44
|
+
require 'dropmark/user'
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module Dropmark
|
4
|
+
class Authentication < Faraday::Middleware
|
5
|
+
|
6
|
+
def initialize(app, options={})
|
7
|
+
@app = app
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
if Dropmark.user_id
|
13
|
+
basic_auth = Base64.encode64([Dropmark.user_id, Dropmark.user_token].join(':')).to_s.gsub!("\n", '')
|
14
|
+
env[:request_headers]["Authorization"] = "Basic #{basic_auth}"
|
15
|
+
end
|
16
|
+
env[:request_headers]["X-API-Key"] = Dropmark.api_key
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Dropmark
|
2
|
+
class Collection
|
3
|
+
include Her::Model
|
4
|
+
uses_api Dropmark.api
|
5
|
+
|
6
|
+
has_many :users
|
7
|
+
has_many :items
|
8
|
+
custom_get :count
|
9
|
+
|
10
|
+
after_find do |i|
|
11
|
+
begin
|
12
|
+
i.created_at = Time.parse(i.created_at)
|
13
|
+
i.updated_at = Time.parse(i.updated_at)
|
14
|
+
i.last_accessed_at = Time.parse(i.last_accessed_at)
|
15
|
+
rescue
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.sort(order)
|
20
|
+
items = put("collections", :order => order)
|
21
|
+
end
|
22
|
+
|
23
|
+
def sort_items(order)
|
24
|
+
items = Dropmark::Item.put("collections/#{id}/items", :order => order)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Dropmark
|
2
|
+
class Comment
|
3
|
+
include Her::Model
|
4
|
+
uses_api Dropmark.api
|
5
|
+
|
6
|
+
collection_path "items/:item_id/comments"
|
7
|
+
resource_path "comments/:id"
|
8
|
+
|
9
|
+
belongs_to :item
|
10
|
+
|
11
|
+
after_find do |i|
|
12
|
+
begin
|
13
|
+
i.created_at = Time.parse(i.created_at)
|
14
|
+
i.updated_at = Time.parse(i.updated_at)
|
15
|
+
rescue
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Dropmark
|
2
|
+
module Error
|
3
|
+
class BadRequest < StandardError; end
|
4
|
+
class Forbidden < StandardError; end
|
5
|
+
class NotFound < StandardError; end
|
6
|
+
class ServerError < StandardError; end
|
7
|
+
|
8
|
+
class RaiseError < Faraday::Response::Middleware
|
9
|
+
def parse(body)
|
10
|
+
if body = MultiJson.load(body, :symbolize_keys => true)
|
11
|
+
body[:message] if body.has_key?(:message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def on_complete(env)
|
16
|
+
return if (status = env[:status]) < 400 # Ignore any non-error response codes
|
17
|
+
|
18
|
+
message = parse(env[:body])
|
19
|
+
case status
|
20
|
+
when 400
|
21
|
+
raise Dropmark::Error::BadRequest, message
|
22
|
+
when 403
|
23
|
+
raise Dropmark::Error::Forbidden, message
|
24
|
+
when 404
|
25
|
+
raise Dropmark::Error::NotFound, message
|
26
|
+
else
|
27
|
+
raise Dropmark::Error::ServerError, message # Treat any other errors as 500
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'mime/types'
|
2
|
+
|
3
|
+
module Dropmark
|
4
|
+
class File < Faraday::UploadIO
|
5
|
+
def initialize(file, mime = nil, filename = nil)
|
6
|
+
if mime.nil? and detected_mimes = MIME::Types.type_for(file)
|
7
|
+
mime = detected_mimes.first
|
8
|
+
end
|
9
|
+
super(file, mime.to_s, filename)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Dropmark
|
2
|
+
class Item
|
3
|
+
include Her::Model
|
4
|
+
uses_api Dropmark.api
|
5
|
+
|
6
|
+
collection_path "collections/:collection_id/items"
|
7
|
+
resource_path "items/:id"
|
8
|
+
|
9
|
+
belongs_to :collection
|
10
|
+
has_many :comments
|
11
|
+
custom_get :count
|
12
|
+
|
13
|
+
method_for :update, :post
|
14
|
+
|
15
|
+
store_metadata :_metadata # conflicted with actual item metadata
|
16
|
+
|
17
|
+
after_initialize do |i|
|
18
|
+
i.metadata = i._metadata unless i.has_attribute?('metadata')
|
19
|
+
begin
|
20
|
+
i.created_at = Time.parse(i.created_at)
|
21
|
+
i.updated_at = Time.parse(i.updated_at)
|
22
|
+
rescue
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.sort(id, order)
|
27
|
+
items = Dropmark::Collection.new(:id => id).sort_items(order)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Dropmark
|
2
|
+
class User
|
3
|
+
include Her::Model
|
4
|
+
uses_api Dropmark.api
|
5
|
+
|
6
|
+
attributes :name, :email, :password, :username
|
7
|
+
validates :name, presence: true
|
8
|
+
validates :email, format: { with: /\A([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}\z/ix }
|
9
|
+
validates :password, length: { minimum: 6 }
|
10
|
+
validates :username, format: { with: /\A(?!-)([a-z0-9-]{0,49}[a-z0-9])\z/i }
|
11
|
+
|
12
|
+
has_many :collections
|
13
|
+
custom_get :contacts
|
14
|
+
|
15
|
+
after_find do |i|
|
16
|
+
begin
|
17
|
+
i.created_at = Time.parse(i.created_at)
|
18
|
+
i.updated_at = Time.parse(i.updated_at)
|
19
|
+
rescue
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def request_path
|
24
|
+
if !Dropmark.user_id.nil? and self.try(:id) == Dropmark.user_id
|
25
|
+
"users/me"
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.auth(params)
|
32
|
+
if response = self.post('auth', params)
|
33
|
+
Dropmark.user_id = response.try(:id)
|
34
|
+
Dropmark.user_token = response.try(:token)
|
35
|
+
end
|
36
|
+
response
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dropmark
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- dropmark
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: her
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mime-types
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: A Ruby interface and command line utility for the Dropmark API.
|
47
|
+
email:
|
48
|
+
- api@dropmark.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- dropmark.gemspec
|
59
|
+
- lib/dropmark.rb
|
60
|
+
- lib/dropmark/authentication.rb
|
61
|
+
- lib/dropmark/collection.rb
|
62
|
+
- lib/dropmark/comment.rb
|
63
|
+
- lib/dropmark/error.rb
|
64
|
+
- lib/dropmark/file.rb
|
65
|
+
- lib/dropmark/item.rb
|
66
|
+
- lib/dropmark/user.rb
|
67
|
+
- lib/dropmark/version.rb
|
68
|
+
homepage: http://dropmark.com
|
69
|
+
licenses: []
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '1.8'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.23
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Dropmark Ruby interface
|
92
|
+
test_files: []
|