paspartout-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDQ0YjJjOTUwZjE4MGNjZDc2OGI1YTc3OTNjZTZkMDM3YWMwOWYzYQ==
5
+ data.tar.gz: !binary |-
6
+ YWYyMjAwZjFkYmZhMTI3OGJkNTZlMzg0M2ZlYWNiZmI3YmE3NDcwNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NDJkMDk2ODYzNzY4NmI5ZjA4MDQ5MDEwYTkzNGU3ZTBjZWEzM2Q4ZjAyMTRm
10
+ ZTRmZTJkZDliMmNkNzNmOTIyYzk3ZDBjZTYwMzRhYTEyMTE0OTllZWUzZmM3
11
+ NGMzZjUxOTdjN2ZlZDY1NmI4ZWZkMDMzOWU5NmI2Y2E2NDhmNmM=
12
+ data.tar.gz: !binary |-
13
+ ZGY0YWUwYzYyOTNkMjgzNDMxNWM0NzYyNWE3MDE4ZTQzZWE0MjAzNjhmMjk4
14
+ MjFlNjFiYTJkNDY5NTBhYWI1ZTg3YjM4ZmYyOWI0Y2FiNTRkNWM0NzUwOWU0
15
+ ZDJkYzUwMjhiNWI5MzJmMGFkZTlkM2Y0NmZjMzI3OGZhYTMyNmU=
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'httparty', '~> 0.12.0'
4
+ gem 'hashie', '~> 2.0.5'
5
+
6
+ group :development do
7
+ gem 'rspec', '~> 2.14.1'
8
+ gem 'rdoc', '~> 3.12'
9
+ gem 'bundler', '~> 1.0'
10
+ gem 'jeweler', '~> 1.8.7'
11
+ gem 'simplecov', '~> 0.8.2'
12
+ end
@@ -0,0 +1,75 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ builder (3.2.2)
6
+ diff-lcs (1.2.5)
7
+ docile (1.1.1)
8
+ faraday (0.8.8)
9
+ multipart-post (~> 1.2.0)
10
+ git (1.2.6)
11
+ github_api (0.10.1)
12
+ addressable
13
+ faraday (~> 0.8.1)
14
+ hashie (>= 1.2)
15
+ multi_json (~> 1.4)
16
+ nokogiri (~> 1.5.2)
17
+ oauth2
18
+ hashie (2.0.5)
19
+ highline (1.6.20)
20
+ httparty (0.12.0)
21
+ json (~> 1.8)
22
+ multi_xml (>= 0.5.2)
23
+ httpauth (0.2.0)
24
+ jeweler (1.8.8)
25
+ builder
26
+ bundler (~> 1.0)
27
+ git (>= 1.2.5)
28
+ github_api (= 0.10.1)
29
+ highline (>= 1.6.15)
30
+ nokogiri (= 1.5.10)
31
+ rake
32
+ rdoc
33
+ json (1.8.1)
34
+ jwt (0.1.8)
35
+ multi_json (>= 1.5)
36
+ multi_json (1.8.2)
37
+ multi_xml (0.5.5)
38
+ multipart-post (1.2.0)
39
+ nokogiri (1.5.10)
40
+ oauth2 (0.9.2)
41
+ faraday (~> 0.8)
42
+ httpauth (~> 0.2)
43
+ jwt (~> 0.1.4)
44
+ multi_json (~> 1.0)
45
+ multi_xml (~> 0.5)
46
+ rack (~> 1.2)
47
+ rack (1.5.2)
48
+ rake (10.1.1)
49
+ rdoc (3.12.2)
50
+ json (~> 1.4)
51
+ rspec (2.14.1)
52
+ rspec-core (~> 2.14.0)
53
+ rspec-expectations (~> 2.14.0)
54
+ rspec-mocks (~> 2.14.0)
55
+ rspec-core (2.14.7)
56
+ rspec-expectations (2.14.4)
57
+ diff-lcs (>= 1.1.3, < 2.0)
58
+ rspec-mocks (2.14.4)
59
+ simplecov (0.8.2)
60
+ docile (~> 1.1.0)
61
+ multi_json
62
+ simplecov-html (~> 0.8.0)
63
+ simplecov-html (0.8.0)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bundler (~> 1.0)
70
+ hashie (~> 2.0.5)
71
+ httparty (~> 0.12.0)
72
+ jeweler (~> 1.8.7)
73
+ rdoc (~> 3.12)
74
+ rspec (~> 2.14.1)
75
+ simplecov (~> 0.8.2)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Wout Fierens
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,55 @@
1
+ # paspartout-api
2
+
3
+ An abstraction layer for the Paspartout API.
4
+
5
+ ## Installation
6
+
7
+ Use RubyGems to install paspartout-api to get started:
8
+
9
+ $ gem install paspartout-api
10
+
11
+ ## Initialization
12
+
13
+ Use the API key of the Paspartout site, found in the settings panel, to establish the connection:
14
+
15
+ @paspartout = Paspartout.new('ppt-247400')
16
+
17
+ ## Pulling data
18
+
19
+ Get the site data:
20
+
21
+ @site = @paspartout.site
22
+
23
+ Get pages in menu:
24
+
25
+ @pages = @paspartout.pages
26
+
27
+ Get a particular page including children or blocks:
28
+
29
+ @page = @paspartout.page(123)
30
+
31
+ This also works with the permaname:
32
+
33
+ @page = @paspartout.page('page-permaname')
34
+
35
+ There are some comvenience methods:
36
+
37
+ @portfolio = @paspartout.portfolio
38
+ @blog = @paspartout.blog
39
+ @shop = @paspartout.shop
40
+ @about = @paspartout.about
41
+
42
+
43
+ ## Contributing to paspartout-api
44
+
45
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
46
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
47
+ * Fork the project.
48
+ * Start a feature/bugfix branch.
49
+ * Commit and push until you are happy with your contribution.
50
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
51
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
52
+
53
+ ## Copyright
54
+
55
+ Copyright (c) 2014 Wout Fierens. See LICENSE.txt for further details.
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "paspartout-api"
18
+ gem.homepage = "http://github.com/wout/paspartout-api"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{An abstraction layer for the Paspartout API}
21
+ gem.description = %Q{An abstraction layer for the Paspartout API}
22
+ gem.email = "wout@impinc.co.uk"
23
+ gem.authors = ["wout"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ # require 'rake/testtask'
29
+ # Rake::TestTask.new(:test) do |test|
30
+ # test.libs << 'lib' << 'spec'
31
+ # test.pattern = 'spec/**/*_spec.rb'
32
+ # test.verbose = true
33
+ # end
34
+
35
+ # require 'rcov/rcovtask'
36
+ # Rcov::RcovTask.new do |test|
37
+ # test.libs << 'test'
38
+ # test.pattern = 'test/**/test_*.rb'
39
+ # test.verbose = true
40
+ # test.rcov_opts << '--exclude "gems/*"'
41
+ # end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "paspartout-api #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,70 @@
1
+ require 'httparty'
2
+ require 'hashie'
3
+
4
+ class Paspartout
5
+
6
+ def initialize api_key
7
+ @api_key = api_key
8
+ @loaded = {}
9
+ end
10
+
11
+ def errors
12
+ @errors
13
+ end
14
+
15
+ def loaded?
16
+ @errors.empty?
17
+ end
18
+
19
+ def site
20
+ return @loaded[:site] if @loaded[:site]
21
+
22
+ if result = get
23
+ @loaded[:site] = result
24
+ end
25
+ end
26
+
27
+ def pages
28
+ return @loaded[:pages] if @loaded[:pages]
29
+
30
+ if result = get('/pages')
31
+ @loaded[:pages] = result
32
+ end
33
+ end
34
+
35
+ def page id
36
+ return @loaded[:"page_#{ id }"] if @loaded[:"page_#{ id }"]
37
+
38
+ if result = get("/pages/#{ id }")
39
+ @loaded[:"page_#{ id }"] = result
40
+ end
41
+ end
42
+
43
+ %w[ portfolio about blog shop ].each do |m|
44
+ define_method m do
45
+ return @loaded[:"#{ m }"] if @loaded[:"#{ m }"]
46
+
47
+ pages.each { |p| @loaded[:"#{ m }"] = page(p.id) if p.type == m }
48
+
49
+ @loaded[:"#{ m }"]
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def get path = ''
56
+ @errors = []
57
+
58
+ request = HTTParty.get("http://api.paspartout.com/public/v2/#{ @api_key }#{ path }.json")
59
+ result = Hashie::Mash.new({ body: JSON.parse(request.body) })
60
+
61
+ if result.error
62
+ @errors.push(result.error)
63
+
64
+ false
65
+ else
66
+ result.body
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rspec'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'paspartout-api'
@@ -0,0 +1,91 @@
1
+ require 'helper'
2
+
3
+ describe Paspartout do
4
+
5
+ before do
6
+ @paspartout = Paspartout.new('ppt-247400')
7
+ end
8
+
9
+ describe '#errors' do
10
+
11
+ it 'fails for non existant sites' do
12
+ @page = @paspartout.page(0)
13
+
14
+ @page.error.code.should be(404)
15
+ end
16
+
17
+ end
18
+
19
+ describe '#site' do
20
+
21
+ it 'loads the site' do
22
+ @paspartout.site.subdomain.should eq('gmc')
23
+ end
24
+
25
+ end
26
+
27
+ describe '#pages' do
28
+
29
+ it 'loads pages' do
30
+ @paspartout.pages.size.should be > 0
31
+ end
32
+
33
+ end
34
+
35
+ describe '#page' do
36
+
37
+ it 'loads a given page by id' do
38
+ @paspartout.page(3077).type.should eq 'portfolio'
39
+ end
40
+
41
+ it 'loads a given page by permaname' do
42
+ @paspartout.page('portfolio').id.should be 3077
43
+ end
44
+
45
+ end
46
+
47
+ describe '#portfolio' do
48
+
49
+ it 'loads the portfolio page' do
50
+ @paspartout.portfolio.id.should be 3077
51
+ end
52
+
53
+ it 'includes children' do
54
+ @paspartout.portfolio.children.any?.should be true
55
+ end
56
+
57
+ end
58
+
59
+ describe '#blog' do
60
+
61
+ it 'loads the blog page' do
62
+ @paspartout.blog.id.should be 3079
63
+ end
64
+
65
+ it 'includes children' do
66
+ @paspartout.blog.children.any?.should be true
67
+ end
68
+
69
+ end
70
+
71
+ describe '#about' do
72
+
73
+ it 'loads the about page' do
74
+ @paspartout.about.id.should be 3078
75
+ end
76
+
77
+ end
78
+
79
+ describe '#shop' do
80
+
81
+ it 'loads the shop page' do
82
+ @paspartout.shop.id.should be 6026
83
+ end
84
+
85
+ it 'includes children' do
86
+ @paspartout.shop.children.any?.should be true
87
+ end
88
+
89
+ end
90
+
91
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paspartout-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - wout
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.7
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.7
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 0.8.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.8.2
111
+ description: An abstraction layer for the Paspartout API
112
+ email: wout@impinc.co.uk
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.md
118
+ files:
119
+ - .document
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - VERSION
126
+ - lib/paspartout-api.rb
127
+ - spec/helper.rb
128
+ - spec/paspartout-api_spec.rb
129
+ homepage: http://github.com/wout/paspartout-api
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.1.9
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: An abstraction layer for the Paspartout API
153
+ test_files: []