phono 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +7 -0
- data/lib/phono/client.rb +62 -51
- data/phono.gemspec +2 -1
- metadata +16 -5
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -69,3 +69,10 @@ Get a resized and cropped version :
|
|
69
69
|
You can also force the resize (with deformation) :
|
70
70
|
|
71
71
|
"#{instance['picture']}?size=300x200&force=true"
|
72
|
+
|
73
|
+
## Cache control
|
74
|
+
|
75
|
+
All JSON responses are cached (5 minutes by default) for performance.
|
76
|
+
You can override this timeout by passing the value you want as a 2nd parameter to the client's constructor :
|
77
|
+
|
78
|
+
Phono::Client.new('424242424242424242424242', 3600) # responses will be cached for 1 hour
|
data/lib/phono/client.rb
CHANGED
@@ -1,56 +1,67 @@
|
|
1
1
|
require 'httparty'
|
2
|
+
require 'httparty-icebox'
|
2
3
|
require 'active_support'
|
4
|
+
require 'active_support/core_ext/hash/keys'
|
3
5
|
|
4
6
|
module Phono
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
7
|
+
class Client
|
8
|
+
include HTTParty
|
9
|
+
include HTTParty::Icebox
|
10
|
+
|
11
|
+
base_uri 'http://phono.phonoid.com/api'
|
12
|
+
|
13
|
+
def initialize(api_key, params = {})
|
14
|
+
@api_key = api_key
|
15
|
+
|
16
|
+
self.class.cache(:timeout => params[:cache_timeout] || 60)
|
17
|
+
end
|
18
|
+
|
19
|
+
def all(ref, params = {})
|
20
|
+
params.stringify_keys!
|
21
|
+
method = params.delete('cache').nil? ? :get : :get_without_caching
|
22
|
+
|
23
|
+
self.class.send(method, "/#{ref}.json", {
|
24
|
+
:query => base_params.merge!(params)
|
25
|
+
})
|
26
|
+
end
|
27
|
+
|
28
|
+
def find(ref, id, params = {})
|
29
|
+
params.stringify_keys!
|
30
|
+
method = params.delete('cache').nil? ? :get : :get_without_caching
|
31
|
+
|
32
|
+
self.class.send(method, "/#{ref}/#{id}.json", {
|
33
|
+
:query => base_params
|
34
|
+
})
|
35
|
+
end
|
36
|
+
|
37
|
+
def create(ref, attributes = {})
|
38
|
+
self.class.post("/#{ref}.json", {
|
39
|
+
:query => base_params.merge!({
|
40
|
+
ref.singularize.to_sym => attributes
|
41
|
+
})
|
42
|
+
})
|
43
|
+
end
|
44
|
+
|
45
|
+
def update(ref, id, params = {})
|
46
|
+
self.class.put("/#{ref}/#{id}.json", {
|
47
|
+
:query => base_params.merge!({
|
48
|
+
ref.singularize.to_sym => attributes
|
49
|
+
})
|
50
|
+
})
|
51
|
+
end
|
52
|
+
|
53
|
+
def destroy(ref, id)
|
54
|
+
self.class.delete("/#{ref}/#{id}.json", {
|
55
|
+
:query => base_params
|
56
|
+
})
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
def base_params
|
62
|
+
{
|
63
|
+
:api_key => @api_key
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
56
67
|
end
|
data/phono.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{phono}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Aurélien Malisart"]
|
@@ -29,5 +29,6 @@ Gem::Specification.new do |s|
|
|
29
29
|
s.specification_version = 3
|
30
30
|
s.add_dependency(%q<httparty>)
|
31
31
|
s.add_dependency(%q<activesupport>, '>= 2.0.0')
|
32
|
+
s.add_dependency(%q<httparty-icebox>)
|
32
33
|
end
|
33
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phono
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-02-04 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &2164742740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2164742740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &2164741160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,18 @@ dependencies:
|
|
32
32
|
version: 2.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2164741160
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: httparty-icebox
|
38
|
+
requirement: &2164739120 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2164739120
|
36
47
|
description: Simple Ruby client for the Phono API
|
37
48
|
email: aurelien.malisart@gmail.com
|
38
49
|
executables: []
|