phono 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *~
2
+ Thumbs.db
3
+ .DS_Store
4
+ *.gem
5
+ .rvmrc
6
+ ~*
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 Aurélien Malisart
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # About
2
+
3
+ Simple Ruby client for the Phono API.
4
+
5
+ # Usage
6
+
7
+ phono = Phono::Client.new('424242424242424242424242')
8
+
9
+ ## Getting all instances of an entity
10
+
11
+ phono.all('products')
12
+
13
+ Results are paginated. You can play with `page` and `per_page` parameters.
14
+
15
+ ### Sorting
16
+
17
+ phono.all('products', {
18
+ 'sort' => 'price.asc'
19
+ })
20
+
21
+ ### Filtering
22
+
23
+ phono.all('products', {
24
+ 'filters' => {
25
+ 'price' => {
26
+ '$lt' => 10.0
27
+ },
28
+
29
+ 'category' => '1234567890ezrzerzrzer'
30
+ }
31
+ })
32
+
33
+ ## Getting a given instance of an entity
34
+
35
+ phono.find('products', '2323...')
36
+
37
+ ## Creating an instance of an entity
38
+
39
+ phono.create('products', {
40
+ 'name' => 'San Pellegrino',
41
+ 'price' => 42.5
42
+ })
43
+
44
+ ## Updating an instance of an entity
45
+
46
+ phono.update('products', '2323...', {
47
+ 'name' => 'San Pellegrino',
48
+ 'price' => 42.5
49
+ })
50
+
51
+ ## Destroying an instance of an entity
52
+
53
+ phono.destroy('products', '2323...')
54
+
55
+ ## Displaying pictures
56
+
57
+ Get the original's URL :
58
+
59
+ instance['picture']
60
+
61
+ Get a resized version :
62
+
63
+ "#{instance['picture']}?size=300x200"
64
+
65
+ Get a resized and cropped version :
66
+
67
+ "#{instance['picture']}?size=300x200&crop=true"
68
+
69
+ You can also force the resize (with deformation) :
70
+
71
+ "#{instance['picture']}?size=300x200&force=true"
data/lib/phono.rb ADDED
@@ -0,0 +1 @@
1
+ require 'phono/client'
@@ -0,0 +1,56 @@
1
+ require 'httparty'
2
+ require 'active_support'
3
+
4
+ module Phono
5
+ class Client
6
+ include HTTParty
7
+
8
+ base_uri 'http://phono.phonoid.com/api'
9
+
10
+ def initialize(api_key)
11
+ @api_key = api_key
12
+ end
13
+
14
+ def all(ref, params = {})
15
+ self.class.get("/#{ref}.json", {
16
+ :query => base_params.merge!(params)
17
+ })
18
+ end
19
+
20
+ def find(ref, id)
21
+ self.class.get("/#{ref}/#{id}.json", {
22
+ :query => base_params
23
+ })
24
+ end
25
+
26
+ def create(ref, attributes = {})
27
+ self.class.post("/#{ref}.json", {
28
+ :query => base_params.merge!({
29
+ ref.singularize.to_sym => attributes
30
+ })
31
+ })
32
+ end
33
+
34
+ def update(ref, id, params = {})
35
+ self.class.put("/#{ref}/#{id}.json", {
36
+ :query => base_params.merge!({
37
+ ref.singularize.to_sym => attributes
38
+ })
39
+ })
40
+ end
41
+
42
+ def destroy(ref, id)
43
+ self.class.delete("/#{ref}/#{id}.json", {
44
+ :query => base_params
45
+ })
46
+ end
47
+
48
+ protected
49
+
50
+ def base_params
51
+ {
52
+ :api_key => @api_key
53
+ }
54
+ end
55
+ end
56
+ end
data/phono.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{phono}
5
+ s.version = "0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Aurélien Malisart"]
9
+ s.date = %q{2012-02-04}
10
+ s.description = %q{Simple Ruby client for the Phono API}
11
+ s.email = %q{aurelien.malisart@gmail.com}
12
+ s.executables = []
13
+
14
+ s.extra_rdoc_files = [
15
+ "README.md"
16
+ ]
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.homepage = %q{http://github.com/aurels/phono}
21
+ s.rdoc_options = ["--charset=UTF-8"]
22
+ s.require_paths = ['lib']
23
+ s.rubygems_version = %q{1.3.7}
24
+ s.summary = %q{Simple Ruby client for the Phono API}
25
+ s.test_files = []
26
+
27
+ if s.respond_to? :specification_version then
28
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
29
+ s.specification_version = 3
30
+ s.add_dependency(%q<httparty>)
31
+ s.add_dependency(%q<activesupport>, '>= 2.0.0')
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phono
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aurélien Malisart
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &2163328660 !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: *2163328660
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &2163328120 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2163328120
36
+ description: Simple Ruby client for the Phono API
37
+ email: aurelien.malisart@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files:
41
+ - README.md
42
+ files:
43
+ - .gitignore
44
+ - LICENSE
45
+ - README.md
46
+ - lib/phono.rb
47
+ - lib/phono/client.rb
48
+ - phono.gemspec
49
+ homepage: http://github.com/aurels/phono
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --charset=UTF-8
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.10
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Simple Ruby client for the Phono API
74
+ test_files: []