sitemandala-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1d9e48af93fdbe00295bcbbbaa0ebeedfee8e4b
4
+ data.tar.gz: 3241d4f41dba7de8e6e02ee2a230f36a53a7461f
5
+ SHA512:
6
+ metadata.gz: fb3ee2235b79ae2c9d7316f20f8fad75da24982a240c0f3e30c4ca54ca5c36dc7cbe2ab06c952ffb5a6298e37814feeaf913e7f34eec25d0979181207e66a42c
7
+ data.tar.gz: 36407262995fe303b65cfc003b3fbdcaa4aefda74b40816a087f0c8d168c202da246404d71386c5820667784dd3f152dde145e90fd9f6b636d4cba3a12f17b46
@@ -0,0 +1,9 @@
1
+ module SiteMandala
2
+
3
+ class Alias < Resource
4
+
5
+ self.resource = 'aliases'
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ module SiteMandala
2
+
3
+ class Blocks < Resource
4
+
5
+ self.resource = 'blocks'
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,34 @@
1
+ module SiteMandala
2
+
3
+ class Configuration
4
+
5
+ class << self
6
+
7
+ attr_reader :token
8
+ attr_reader :base_url
9
+
10
+ def configure(config)
11
+ config.stringify_keys!
12
+ @token = config["token"]
13
+ @base_url = config["base_url"] || "https://api.sitemandala.com"
14
+ self
15
+ end
16
+
17
+ def reset!
18
+ @token = nil
19
+ @base_url = "https://api.sitemandala.com"
20
+ end
21
+
22
+ def ensure!(*params)
23
+ params.each do |p|
24
+ raise SiteMandala::ConfigurationError.new("'#{p}' not configured") unless instance_variable_get "@#{p}"
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ reset!
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,9 @@
1
+ module SiteMandala
2
+
3
+ class Contacts < Resource
4
+
5
+ self.resource = 'contacts'
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ module SiteMandala
2
+
3
+ class Pages < Resource
4
+
5
+ self.resource = 'pages'
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ module SiteMandala
2
+
3
+ class Posts < Resource
4
+
5
+ self.resource = 'posts'
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,33 @@
1
+ module SiteMandala
2
+
3
+ class Resource
4
+
5
+ class << self
6
+
7
+ attr_accessor :resource
8
+
9
+ end
10
+
11
+ def self.all
12
+ SiteMandala.get("/admin/#{resource}")
13
+ end
14
+
15
+ def self.find(id)
16
+ SiteMandala.get("/admin/#{resource}/#{id}")
17
+ end
18
+
19
+ def self.create(data)
20
+ SiteMandala.post("/admin/#{resource}", data)
21
+ end
22
+
23
+ def self.update(id, data)
24
+ SiteMandala.patch("/admin/#{resource}/#{id}", data)
25
+ end
26
+
27
+ def self.delete(id)
28
+ SiteMandala.delete("/admin/#{resource}/#{id}")
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,80 @@
1
+ module SiteMandala
2
+
3
+ class SiteMandalaError < StandardError
4
+ attr_reader :data
5
+ def initialize(data)
6
+ @data = data
7
+ extra = @data.ResultData ? "\nExtra result data: #{@data.ResultData}" : ""
8
+ super "The SiteMandala API responded with the following error - #{@data.Code}: #{@data.Message}#{extra}"
9
+ end
10
+ end
11
+
12
+ class ClientError < StandardError; end
13
+ class ServerError < StandardError; end
14
+ class BadRequest < SiteMandalaError; end
15
+ class Unauthorized < SiteMandalaError; end
16
+ class NotFound < ClientError; end
17
+ class InvalidOAuthToken < Unauthorized; end
18
+ class ExpiredOAuthToken < Unauthorized; end
19
+ class RevokedOAuthToken < Unauthorized; end
20
+
21
+ class SiteMandala
22
+
23
+ class << self
24
+
25
+ attr_accessor :token
26
+
27
+ end
28
+
29
+ def self.get(endpoint)
30
+ url = generate_url(endpoint)
31
+ handle_response HTTParty.get(url, :format => :json)
32
+ end
33
+
34
+ def self.post(endpoint, data)
35
+ url = generate_url(endpoint)
36
+ handle_response HTTParty.post(url, :body => data.to_json, :format => :json)
37
+ end
38
+
39
+ def self.put(endpoint, data)
40
+ url = generate_url(endpoint)
41
+ handle_response HTTParty.put(url, :body => data.to_json, :format => :json)
42
+ end
43
+
44
+ def self.patch(endpoint, data)
45
+ url = generate_url(endpoint)
46
+ handle_response HTTParty.patch(url, :body => data.to_json, :format => :json)
47
+ end
48
+
49
+ def self.delete(endpoint)
50
+ url = generate_url(endpoint)
51
+ handle_response HTTParty.delete(url, :format => :json)
52
+ end
53
+
54
+ def self.generate_url(endpoint)
55
+ Configuration.ensure! :base_url
56
+ Configuration.ensure! :token
57
+ token = Configuration.token
58
+ base_url = Configuration.base_url
59
+ base_url+endpoint+"?token="+token
60
+ end
61
+
62
+ def self.handle_response(response)
63
+ case response.code
64
+ when 400
65
+ raise BadRequest.new(Hashie::Mash.new response)
66
+ when 401
67
+ data = Hashie::Mash.new(response)
68
+ when 404
69
+ raise NotFound.new
70
+ when 400...500
71
+ raise ClientError.new
72
+ when 500...600
73
+ raise ServerError.new
74
+ else
75
+ response.parsed_response
76
+ end
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,20 @@
1
+ require 'active_support/core_ext'
2
+ require 'httparty'
3
+ require 'sitemandala/configuration'
4
+ require 'sitemandala/sitemandala'
5
+ require 'sitemandala/resource'
6
+ require 'sitemandala/aliases'
7
+ require 'sitemandala/blocks'
8
+ require 'sitemandala/contacts'
9
+ require 'sitemandala/pages'
10
+ require 'sitemandala/posts'
11
+
12
+ module SiteMandala
13
+
14
+ def self.configure(config={})
15
+
16
+ Configuration.configure(config)
17
+
18
+ end
19
+
20
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sitemandala-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Greg Kops
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'A Ruby library for the Site Mandala API '
14
+ email: greg@thinktopography.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/sitemandala.rb
20
+ - lib/sitemandala/aliases.rb
21
+ - lib/sitemandala/blocks.rb
22
+ - lib/sitemandala/configuration.rb
23
+ - lib/sitemandala/contacts.rb
24
+ - lib/sitemandala/pages.rb
25
+ - lib/sitemandala/posts.rb
26
+ - lib/sitemandala/resource.rb
27
+ - lib/sitemandala/sitemandala.rb
28
+ homepage: http://rubygems.org/gems/sitemandala
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.4.4
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Site Mandala Ruby Gem
52
+ test_files: []