typefront 0.1.0

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.
@@ -0,0 +1,20 @@
1
+ Copyright (c) Small Spark Pty Ltd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # TypeFront for Ruby and Ruby on Rails
2
+
3
+ This is a wrapper around TypeFront's RESTful API for adding, removing, updating and getting details about your fonts being served by [TypeFront](http://typefront.com).
4
+
5
+ Check out the [TypeFront API Documentation](http://typefront.com/documentation) for more information.
6
+
7
+ ## Installation
8
+
9
+ `gem install typefront`
10
+
11
+ ## Configuration
12
+
13
+ In your environment.rb:
14
+
15
+ `TypeFront.settings = {
16
+ :email => 'YOUR EMAIL HERE',
17
+ :password => 'YOUR PASSWORD HERE'
18
+ }`
19
+
20
+ ### Getting a listing of your fonts
21
+
22
+ `TypeFront.fonts`
23
+
24
+ ### Getting the details of a font
25
+
26
+ `TypeFront.font_details(101)`
27
+
28
+ ### Uploading a new font
29
+
30
+ `TypeFront.upload_font(File.new('somefont.ttf'))`
31
+
32
+ ### Remove font
33
+
34
+ `TypeFront.remove_font(101)`
35
+
36
+ ### Add new allowed domain
37
+
38
+ `TypeFront.add_domain(101, 'http://somedomain.com')`
39
+
40
+ ### Remove allowed domain
41
+
42
+ `TypeFront.remove_domain(101, 201)`
43
+
44
+ ---
45
+
46
+ Copyright (c) 2010 Small Spark Pty Ltd, released under the MIT license
@@ -0,0 +1,20 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc 'Test the typefront gem.'
9
+ Spec::Rake::SpecTask.new do |t|
10
+ t.spec_opts = ['--options', File.join(File.dirname(__FILE__), %w(spec spec.opts))]
11
+ end
12
+
13
+ desc 'Generate documentation for the typefront gem.'
14
+ Rake::RDocTask.new(:rdoc) do |rdoc|
15
+ rdoc.rdoc_dir = 'rdoc'
16
+ rdoc.title = 'TypeFront'
17
+ rdoc.options << '--line-numbers' << '--inline-source'
18
+ rdoc.rdoc_files.include('README')
19
+ rdoc.rdoc_files.include('lib/**/*.rb')
20
+ end
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'restclient'
3
+ require 'json'
4
+
5
+ class TypeFrontException < Exception; end
6
+
7
+ class TypeFront
8
+ VERSION = '0.1.0'
9
+ DOMAIN = 'http://typefront.local:3000'
10
+
11
+ def initialize(email, password)
12
+ @default_options = {
13
+ :user => email,
14
+ :password => password,
15
+ :content_type => :json,
16
+ :accept => :json,
17
+ :headers => { :user_agent => "typefront-ruby/#{VERSION}" }
18
+ }
19
+ @resource = RestClient::Resource.new("#{DOMAIN}", @default_options)
20
+ end
21
+
22
+ def fonts
23
+ get('/fonts.json')
24
+ end
25
+
26
+ def font_details(font_id)
27
+ get("/fonts/#{font_id}.json")
28
+ end
29
+
30
+ def upload_font(file)
31
+ post('/fonts.json', :font => { :original => file })
32
+ end
33
+
34
+ def remove_font(font_id)
35
+ delete("/fonts/#{font_id}.json")
36
+ end
37
+
38
+ def add_domain(font_id, domain)
39
+ post("/fonts/#{font_id}/domains.json", :domain => { :domain => domain })
40
+ end
41
+
42
+ def remove_domain(font_id, domain_id)
43
+ delete("/fonts/#{font_id}/domains/#{domain_id}.json")
44
+ end
45
+
46
+ private
47
+
48
+ def method_missing(name, *args)
49
+ if [:get, :post, :delete].include?(name)
50
+ send(:send_request, name, args[0], args[1] ? args[1] : {})
51
+ else
52
+ super
53
+ end
54
+ end
55
+
56
+ def send_request(method, subpath = nil, options = {})
57
+ response = @resource[subpath].send(method, options)
58
+ JSON.parse(response)
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ --colour
2
+ --format specdoc
3
+ --loadby mtime
4
+ --reverse
5
+ --backtrace
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'typefront'
4
+
5
+ Spec::Runner.configure do |config|
6
+ config.mock_with :mocha
7
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe TypeFront do
4
+ before(:all) do
5
+ @typefront = TypeFront.new('username', 'password')
6
+ end
7
+
8
+ before do
9
+ JSON.expects(:parse).once
10
+ end
11
+
12
+ describe 'fonts' do
13
+ it 'should run successfully' do
14
+ RestClient::Resource.any_instance.expects(:get)
15
+ @typefront.fonts
16
+ end
17
+ end
18
+
19
+ describe 'font_details' do
20
+ it 'should run successfully' do
21
+ RestClient::Resource.any_instance.expects(:get)
22
+ @typefront.font_details(101)
23
+ end
24
+ end
25
+
26
+ describe 'upload_font' do
27
+ it 'should run successfully' do
28
+ RestClient::Resource.any_instance.expects(:post)
29
+ file = mock()
30
+ @typefront.upload_font(file)
31
+ end
32
+ end
33
+
34
+ describe 'remove_font' do
35
+ it 'should run successfully' do
36
+ RestClient::Resource.any_instance.expects(:delete)
37
+ @typefront.remove_font(101)
38
+ end
39
+ end
40
+
41
+ describe 'add_domain' do
42
+ it 'should run successfully' do
43
+ RestClient::Resource.any_instance.expects(:post)
44
+ @typefront.add_domain(101, 201)
45
+ end
46
+ end
47
+
48
+ describe 'remove_domain' do
49
+ it 'should run successfully' do
50
+ RestClient::Resource.any_instance.expects(:delete)
51
+ @typefront.remove_domain(101, 201)
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typefront
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Small Spark
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-20 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rest-client
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 5
30
+ - 0
31
+ version: 1.5.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: json
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 4
44
+ - 3
45
+ version: 1.4.3
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ type: :development
59
+ version_requirements: *id003
60
+ description: A Ruby library for interacting with the TypeFront API.
61
+ email: contact@smallspark.com.au
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files: []
67
+
68
+ files:
69
+ - MIT-LICENSE
70
+ - Rakefile
71
+ - README.markdown
72
+ - lib/typefront.rb
73
+ - spec/spec.opts
74
+ - spec/spec_helper.rb
75
+ - spec/typefront_spec.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/smallspark/typefront-ruby
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options: []
82
+
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.3.6
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: A Ruby library for interacting with the TypeFront API.
106
+ test_files:
107
+ - spec/spec_helper.rb
108
+ - spec/typefront_spec.rb