chute 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README +125 -0
- data/Rakefile +11 -0
- data/chute.gemspec +22 -0
- data/config/chute.rb +0 -0
- data/lib/chute.rb +22 -0
- data/lib/chute/account.rb +58 -0
- data/lib/chute/app.rb +32 -0
- data/lib/chute/asset.rb +124 -0
- data/lib/chute/bundle.rb +72 -0
- data/lib/chute/chute.rb +203 -0
- data/lib/chute/collection.rb +47 -0
- data/lib/chute/comment.rb +32 -0
- data/lib/chute/exception.rb +7 -0
- data/lib/chute/http_service.rb +114 -0
- data/lib/chute/inbox.rb +41 -0
- data/lib/chute/parcel.rb +45 -0
- data/lib/chute/resource.rb +354 -0
- data/lib/chute/user.rb +113 -0
- data/lib/chute/util.rb +14 -0
- data/lib/chute/version.rb +3 -0
- data/test/test_sudoku.rb +7 -0
- metadata +69 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
Setup
|
2
|
+
====
|
3
|
+
|
4
|
+
1. Add to Gemfile
|
5
|
+
|
6
|
+
gem install chute
|
7
|
+
|
8
|
+
2. Add configuration file 'config/chute.rb' with the following details:
|
9
|
+
|
10
|
+
API_URL = "ADD API URL HERE"
|
11
|
+
API_KEY = "ADD ACCESS TOKEN HERE"
|
12
|
+
|
13
|
+
|
14
|
+
Key Concepts
|
15
|
+
========
|
16
|
+
|
17
|
+
## Client
|
18
|
+
All Chute applications use OAuth and are referred to as 'Clients'
|
19
|
+
|
20
|
+
## Chute
|
21
|
+
A container for assets. Chutes can be nested inside of each other.
|
22
|
+
|
23
|
+
#initialize
|
24
|
+
account= Chute::GCChute.new({:name => "Test chute"})
|
25
|
+
|
26
|
+
#create chute
|
27
|
+
#if successful, chute is created
|
28
|
+
#if unsuccessful account.errors contains the details
|
29
|
+
chute.create
|
30
|
+
|
31
|
+
|
32
|
+
## Asset
|
33
|
+
Any photo or video managed by Chute
|
34
|
+
|
35
|
+
#Find assets for a chute
|
36
|
+
#Returns collection of GCAsset
|
37
|
+
chute.assets
|
38
|
+
|
39
|
+
## Parcel
|
40
|
+
A named collection of assets. Whenever you upload assets, they are grouped into parcels.
|
41
|
+
|
42
|
+
## Bundle
|
43
|
+
An unnamed collection of assets.
|
44
|
+
|
45
|
+
#initialize a bundle
|
46
|
+
bundle = Chute::GCBundle.new
|
47
|
+
|
48
|
+
#prefix the asset_ids for the bundle
|
49
|
+
#string - array of asset_ids
|
50
|
+
bundle.prefix_options = '["34", "56"]'
|
51
|
+
|
52
|
+
#create the bundle
|
53
|
+
#if successful, returns the newly created bundle
|
54
|
+
#if unsuccessful, bundle.errors contains errors or raises an exception
|
55
|
+
bundle.save
|
56
|
+
|
57
|
+
bundle.id # id of the bundle
|
58
|
+
|
59
|
+
#find a bundle
|
60
|
+
bundle = Chute::GCBundle.find_by_id(id)
|
61
|
+
|
62
|
+
#add assets to bundle
|
63
|
+
#bundle.add_assets(array_of_asset_ids)
|
64
|
+
#returns the new set of assets
|
65
|
+
bundle.add_assets(["11", "22", "45"])
|
66
|
+
|
67
|
+
#remove assets from bundle
|
68
|
+
#bundle.remove_assets(array_of_asset_ids)
|
69
|
+
#returns the new set of assets
|
70
|
+
bundle.remove_assets(["22", "3"])
|
71
|
+
|
72
|
+
|
73
|
+
Basic Tasks
|
74
|
+
=========
|
75
|
+
|
76
|
+
## Uploading Assets
|
77
|
+
|
78
|
+
## Displaying Assets
|
79
|
+
|
80
|
+
## Organizing Assets
|
81
|
+
|
82
|
+
## Associating Your Data with Assets
|
83
|
+
|
84
|
+
## Bundling Assets
|
85
|
+
#find a bundle
|
86
|
+
bundle = Chute::GCBundle.find_by_id(id)
|
87
|
+
|
88
|
+
#add assets to bundle
|
89
|
+
#bundle.add_assets(array_of_asset_ids)
|
90
|
+
#returns the new set of assets
|
91
|
+
bundle.add_assets(["11", "22", "45"])
|
92
|
+
|
93
|
+
#remove assets from bundle
|
94
|
+
#bundle.remove_assets(array_of_asset_ids)
|
95
|
+
#returns the new set of assets
|
96
|
+
bundle.remove_assets(["22", "3"])
|
97
|
+
|
98
|
+
|
99
|
+
Social Tasks
|
100
|
+
==========
|
101
|
+
|
102
|
+
## Hearting Assets
|
103
|
+
|
104
|
+
#heart
|
105
|
+
# id - Asset Identifier
|
106
|
+
Chute::GCAsset.heart(id)
|
107
|
+
|
108
|
+
#unheart
|
109
|
+
Chute::GCAsset.unheart(id)
|
110
|
+
|
111
|
+
## Commenting on Assets
|
112
|
+
|
113
|
+
#add a comment for an asset in a chute
|
114
|
+
#chute.add_comment(comment_text, asset_id)
|
115
|
+
|
116
|
+
chute.add_comment("test comment 2", 37)
|
117
|
+
|
118
|
+
#find a comment
|
119
|
+
comments = chute.comments(37)
|
120
|
+
comment = comments.first
|
121
|
+
|
122
|
+
#delete comment
|
123
|
+
comment.destroy
|
124
|
+
|
125
|
+
|
data/Rakefile
ADDED
data/chute.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "chute/version"
|
4
|
+
require "httparty"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "chute"
|
8
|
+
s.version = Chute::VERSION
|
9
|
+
s.authors = ["Payal Gupta"]
|
10
|
+
s.email = ["payal@getchute.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Chute API Integration}
|
13
|
+
s.description = %q{This gem allows to map your models with a chute.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "chute"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
#s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.test_files = Dir.glob("test/**/*.rb")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
end
|
data/config/chute.rb
ADDED
File without changes
|
data/lib/chute.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#require "chute/version"
|
2
|
+
#require "httparty"
|
3
|
+
|
4
|
+
# include utility modules
|
5
|
+
require 'chute/util'
|
6
|
+
require 'chute/http_service'
|
7
|
+
require 'chute/collection'
|
8
|
+
require 'chute/exception'
|
9
|
+
|
10
|
+
# include chute modules
|
11
|
+
|
12
|
+
# base class
|
13
|
+
require 'chute/resource'
|
14
|
+
require 'chute/chute'
|
15
|
+
require 'chute/asset'
|
16
|
+
require 'chute/account'
|
17
|
+
require 'chute/bundle'
|
18
|
+
require 'chute/comment'
|
19
|
+
require 'chute/parcel'
|
20
|
+
require 'chute/user'
|
21
|
+
require 'chute/app'
|
22
|
+
require 'chute/inbox'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Chute
|
2
|
+
class GCAccount < GCResource
|
3
|
+
|
4
|
+
attr_accessor :id,
|
5
|
+
:uid,
|
6
|
+
:type,
|
7
|
+
:email,
|
8
|
+
:name,
|
9
|
+
:access_key,
|
10
|
+
:notifications_enabled
|
11
|
+
|
12
|
+
def initialize(attributes = {})
|
13
|
+
super
|
14
|
+
@id = attributes[:id]
|
15
|
+
@uid = attributes[:uid]
|
16
|
+
@email = attributes[:email]
|
17
|
+
@name = attributes[:name]
|
18
|
+
@access_key = attributes[:access_key]
|
19
|
+
@notifications_enabled = attributes[:notifications_enabled]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Public: Pluralized name of the resource.
|
23
|
+
def resource_name
|
24
|
+
'accounts'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Public: Disable notifications for the account
|
28
|
+
def mute
|
29
|
+
perform(self.class.post("/#{resource_name}/#{id}/mute"))
|
30
|
+
end
|
31
|
+
|
32
|
+
# Public: Enable notifications for the account
|
33
|
+
def unmute
|
34
|
+
perform(self.class.post("/#{resource_name}/#{id}/unmute"))
|
35
|
+
end
|
36
|
+
|
37
|
+
# Public: Pluralized name of the resource.
|
38
|
+
def self.class_path
|
39
|
+
"accounts"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Public: Fetch account from its id.
|
43
|
+
# id - Integer: identifier.
|
44
|
+
#
|
45
|
+
# Example
|
46
|
+
#
|
47
|
+
# Chute::GAccount.find_by_id(23)
|
48
|
+
# # => account
|
49
|
+
# # => false if not found
|
50
|
+
# Returns GCAccount.
|
51
|
+
|
52
|
+
def self.find_by_id(id)
|
53
|
+
account = Chute::GCAccount.new
|
54
|
+
account.perform(get("/accounts/#{id}")) ? account : false
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
data/lib/chute/app.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Chute
|
2
|
+
class GCApp < GCResource
|
3
|
+
|
4
|
+
def save
|
5
|
+
raise NotImplementedError
|
6
|
+
end
|
7
|
+
|
8
|
+
def update
|
9
|
+
raise NotImplementedError
|
10
|
+
end
|
11
|
+
|
12
|
+
def destroy
|
13
|
+
raise NotImplementedError
|
14
|
+
end
|
15
|
+
|
16
|
+
# Public: Resource name
|
17
|
+
def resource_name
|
18
|
+
'app'
|
19
|
+
end
|
20
|
+
|
21
|
+
# Public: Resource name
|
22
|
+
def resource_path
|
23
|
+
'app'
|
24
|
+
end
|
25
|
+
|
26
|
+
# Public: Resource name
|
27
|
+
def class_path
|
28
|
+
'app'
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/chute/asset.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
module Chute
|
2
|
+
class GCAsset < GCResource
|
3
|
+
|
4
|
+
attr_accessor :id,
|
5
|
+
:url,
|
6
|
+
:share_url,
|
7
|
+
:is_portrait
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
super
|
11
|
+
@id = attributes[:id]
|
12
|
+
@url = attributes[:url]
|
13
|
+
@share_url = attributes[:share_url]
|
14
|
+
@is_portrait = attributes[:is_portrait]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Public: Returns pluralized name of the resource.
|
18
|
+
def resource_name
|
19
|
+
'assets'
|
20
|
+
end
|
21
|
+
|
22
|
+
# Public: Relative url of an asset for a custom geometry
|
23
|
+
#
|
24
|
+
# height - Integer: height of the asset images
|
25
|
+
# width - String: width of the asset image
|
26
|
+
#
|
27
|
+
# Examples
|
28
|
+
#
|
29
|
+
# asset.url = "asset url"
|
30
|
+
# asset.custom_url(200, 300)
|
31
|
+
# # => "asset url/200x300"
|
32
|
+
# Returns the url to the custom image
|
33
|
+
|
34
|
+
def custom_url(height, width)
|
35
|
+
"#{url}/#{height}x#{width}" if url
|
36
|
+
end
|
37
|
+
|
38
|
+
#================================================#
|
39
|
+
# Class Methods #
|
40
|
+
#================================================#
|
41
|
+
|
42
|
+
# Public: Fetch asset from its id.
|
43
|
+
# id - Integer: identifier.
|
44
|
+
#
|
45
|
+
# Example
|
46
|
+
#
|
47
|
+
# Chute::GCAsset.find_by_id(23)
|
48
|
+
# # => asset
|
49
|
+
# # => false if not found
|
50
|
+
# Returns GCAsset
|
51
|
+
|
52
|
+
def self.find_by_id(id)
|
53
|
+
asset = Chute::GCAsset.new
|
54
|
+
asset.perform(get("/assets/#{id}")) ? asset : false
|
55
|
+
end
|
56
|
+
|
57
|
+
# Public: Returns pluralized name of the resource.
|
58
|
+
def self.class_path
|
59
|
+
"assets"
|
60
|
+
end
|
61
|
+
|
62
|
+
# Public: Make asset as favorite
|
63
|
+
# id - Identifier.
|
64
|
+
#
|
65
|
+
# Example
|
66
|
+
#
|
67
|
+
# Chute::GCAsset.heart(23)
|
68
|
+
# # => true
|
69
|
+
# Returns boolean true or false
|
70
|
+
|
71
|
+
def self.heart(id)
|
72
|
+
response = get("/assets/#{id}/heart")
|
73
|
+
response.is_success
|
74
|
+
end
|
75
|
+
|
76
|
+
# Public: Remove asset as favorite
|
77
|
+
# id - Identifier.
|
78
|
+
#
|
79
|
+
# Example
|
80
|
+
#
|
81
|
+
# Chute::GCAsset.unheart(23)
|
82
|
+
# # => true
|
83
|
+
# Returns boolean true or false
|
84
|
+
|
85
|
+
def self.unheart(id)
|
86
|
+
response = get("/assets/#{id}/unheart")
|
87
|
+
response.is_success
|
88
|
+
end
|
89
|
+
|
90
|
+
# Public: Remove assets
|
91
|
+
# ids - Array: Identifier list
|
92
|
+
#
|
93
|
+
# Example
|
94
|
+
#
|
95
|
+
# Chute::GCAsset.remove([1, 23, 56])
|
96
|
+
# # => true
|
97
|
+
# Returns boolean true or false
|
98
|
+
|
99
|
+
def self.remove(ids=[])
|
100
|
+
response = post("/assets/remove", {:asset_ids => ids})
|
101
|
+
response.is_success
|
102
|
+
end
|
103
|
+
|
104
|
+
# Public: Verify assets
|
105
|
+
# files - Array: [URL, size, md5]
|
106
|
+
#
|
107
|
+
# Example
|
108
|
+
#
|
109
|
+
# files = [{
|
110
|
+
# :url => "Users/payalgupta/Desktop/39-Dcroe.jpg",
|
111
|
+
# :size => 34500,
|
112
|
+
# :md5 => 34500
|
113
|
+
# }]
|
114
|
+
# Chute::GCAsset.verify(files)
|
115
|
+
# # => true
|
116
|
+
# Returns boolean true or false
|
117
|
+
|
118
|
+
def self.verify(files=[])
|
119
|
+
response = post("/assets/verify", {:files => files})
|
120
|
+
response.is_success
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
data/lib/chute/bundle.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Chute
|
2
|
+
class GCBundle < GCResource
|
3
|
+
attr_accessor :id,
|
4
|
+
:url,
|
5
|
+
:shortcut
|
6
|
+
|
7
|
+
def initialize(attributes={})
|
8
|
+
super
|
9
|
+
@id = attributes[:id]
|
10
|
+
@url = attributes[:url]
|
11
|
+
@shortcut = attributes[:shortcut]
|
12
|
+
end
|
13
|
+
|
14
|
+
# Public: Returns pluralized name of the resource.
|
15
|
+
def resource_name
|
16
|
+
'bundles'
|
17
|
+
end
|
18
|
+
|
19
|
+
def destroy
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
|
23
|
+
# Public: Add assets to a bundle
|
24
|
+
# asset_ids - Array: Identifier list of assets
|
25
|
+
#
|
26
|
+
# Example
|
27
|
+
#
|
28
|
+
# Chute::GCBundle.add_assets([1, 23, 56])
|
29
|
+
# # => true
|
30
|
+
# Returns boolean true or false
|
31
|
+
|
32
|
+
def add_assets(asset_ids)
|
33
|
+
response = self.class.post("/bundles/#{id}/add", :asset_ids => "#{asset_ids}")
|
34
|
+
response.is_success
|
35
|
+
end
|
36
|
+
|
37
|
+
# Public: Remove assets from a bundle
|
38
|
+
# asset_ids - Array: Identifier list of assets
|
39
|
+
#
|
40
|
+
# Example
|
41
|
+
#
|
42
|
+
# Chute::GCBundle.remove_assets([1, 23, 56])
|
43
|
+
# # => true
|
44
|
+
# Returns boolean true or false
|
45
|
+
|
46
|
+
def remove_assets(asset_ids)
|
47
|
+
response = self.class.post("/bundles/#{id}/remove", :asset_ids => "#{asset_ids}")
|
48
|
+
response.is_success
|
49
|
+
end
|
50
|
+
|
51
|
+
# Public: Fetch bundle from its id.
|
52
|
+
# id - Integer: identifier.
|
53
|
+
#
|
54
|
+
# Example
|
55
|
+
#
|
56
|
+
# Chute::GCBundle.find_by_id(23)
|
57
|
+
# # => bundle
|
58
|
+
# # => false if not found
|
59
|
+
# Returns GCBundle
|
60
|
+
|
61
|
+
def self.find_by_id(id)
|
62
|
+
bundle = Chute::GCBundle.new
|
63
|
+
bundle.perform(get("/bundles/#{id}")) ? bundle : false
|
64
|
+
end
|
65
|
+
|
66
|
+
# Public: Returns pluralized name of the resource.
|
67
|
+
def self.class_path
|
68
|
+
"bundles"
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|