admincredible 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +12 -0
- data/Gemfile.lock +86 -0
- data/Rakefile +24 -0
- data/Readme.md +121 -0
- data/TODOS +1 -0
- data/admincredible.gemspec +35 -0
- data/developer_notes/README.md +2 -0
- data/developer_notes/TODOS.md +0 -0
- data/lib/admincredible.rb +1 -0
- data/lib/admincredible/client.rb +60 -0
- data/lib/admincredible/configuration.rb +125 -0
- data/lib/admincredible/connection.rb +30 -0
- data/lib/admincredible/core_ext/string.rb +16 -0
- data/lib/admincredible/joomla_request.rb +22 -0
- data/lib/admincredible/middleware/logger.rb +51 -0
- data/lib/admincredible/middleware/step.rb +44 -0
- data/lib/admincredible/request.rb +47 -0
- data/lib/admincredible/resource.rb +20 -0
- data/lib/admincredible/resources/Backup.rb +34 -0
- data/lib/admincredible/resources/Compatibility.rb +13 -0
- data/lib/admincredible/resources/Extension.rb +37 -0
- data/lib/admincredible/resources/Oauth.rb +53 -0
- data/lib/admincredible/resources/Setting.rb +21 -0
- data/lib/admincredible/resources/Site.rb +9 -0
- data/lib/admincredible/resources/Upgrade.rb +64 -0
- data/spec/core/client_spec.rb +24 -0
- data/spec/core/resource_spec.rb +13 -0
- data/spec/fixtures/cassettes/backups/create.yml +73 -0
- data/spec/fixtures/cassettes/backups/start.yml +38 -0
- data/spec/fixtures/cassettes/backups/step.yml +38 -0
- data/spec/fixtures/cassettes/compatibility/added_exceptions.yml +38 -0
- data/spec/fixtures/cassettes/compatibility/status.yml +38 -0
- data/spec/fixtures/cassettes/extensions/all.yml +38 -0
- data/spec/fixtures/cassettes/extensions/update.yml +38 -0
- data/spec/fixtures/cassettes/settings/all.yml +38 -0
- data/spec/fixtures/cassettes/settings/created.yml +39 -0
- data/spec/fixtures/cassettes/settings/first.yml +38 -0
- data/spec/fixtures/cassettes/settings/updated.yml +39 -0
- data/spec/fixtures/cassettes/site/configuration.yml +41 -0
- data/spec/fixtures/cassettes/upgrade/cleanup.yml +38 -0
- data/spec/fixtures/cassettes/upgrade/create.yml +249 -0
- data/spec/fixtures/cassettes/upgrade/create_restoration_file.yml +38 -0
- data/spec/fixtures/cassettes/upgrade/download.yml +38 -0
- data/spec/fixtures/cassettes/upgrade/finalize.yml +38 -0
- data/spec/fixtures/cassettes/upgrade/info.yml +38 -0
- data/spec/fixtures/cassettes/upgrade/start.yml +39 -0
- data/spec/fixtures/cassettes/upgrade/step.yml +38 -0
- data/spec/resources/backups_spec.rb +36 -0
- data/spec/resources/compatibility_spec.rb +25 -0
- data/spec/resources/extensions_spec.rb +25 -0
- data/spec/resources/setting_spec.rb +47 -0
- data/spec/resources/site_spec.rb +14 -0
- data/spec/resources/upgrade_spec.rb +91 -0
- data/spec/spec_helper.rb +38 -0
- metadata +353 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/bookworm/roauth.git
|
3
|
+
revision: 6e67a5909cf560312f69d2d066b4e477c14d23d5
|
4
|
+
specs:
|
5
|
+
roauth (0.0.7)
|
6
|
+
|
7
|
+
PATH
|
8
|
+
remote: .
|
9
|
+
specs:
|
10
|
+
admincredible (0.0.1)
|
11
|
+
active_support
|
12
|
+
faraday (>= 0.8.0)
|
13
|
+
faraday_middleware (>= 0.8.7)
|
14
|
+
hashie
|
15
|
+
inflection
|
16
|
+
json
|
17
|
+
mime-types
|
18
|
+
multipart-post
|
19
|
+
simple_oauth
|
20
|
+
|
21
|
+
GEM
|
22
|
+
remote: http://rubygems.org/
|
23
|
+
specs:
|
24
|
+
active_support (3.0.0)
|
25
|
+
activesupport (= 3.0.0)
|
26
|
+
activemodel (3.0.0)
|
27
|
+
activesupport (= 3.0.0)
|
28
|
+
builder (~> 2.1.2)
|
29
|
+
i18n (~> 0.4.1)
|
30
|
+
activesupport (3.0.0)
|
31
|
+
addressable (2.3.2)
|
32
|
+
bond (0.4.3)
|
33
|
+
bson (1.8.1)
|
34
|
+
builder (2.1.2)
|
35
|
+
crack (0.3.2)
|
36
|
+
diff-lcs (1.1.3)
|
37
|
+
faraday (0.8.4)
|
38
|
+
multipart-post (~> 1.1)
|
39
|
+
faraday_middleware (0.9.0)
|
40
|
+
faraday (>= 0.7.4, < 0.9)
|
41
|
+
hashie (1.2.0)
|
42
|
+
i18n (0.4.2)
|
43
|
+
inflection (1.0.0)
|
44
|
+
json (1.7.6)
|
45
|
+
mime-types (1.19)
|
46
|
+
mongo (1.8.1)
|
47
|
+
bson (~> 1.8.1)
|
48
|
+
mongo_mapper (0.12.0)
|
49
|
+
activemodel (~> 3.0)
|
50
|
+
activesupport (~> 3.0)
|
51
|
+
plucky (~> 0.5.2)
|
52
|
+
multipart-post (1.1.5)
|
53
|
+
nestful (0.0.8)
|
54
|
+
activesupport (>= 3.0.0.beta)
|
55
|
+
plucky (0.5.2)
|
56
|
+
mongo (~> 1.5)
|
57
|
+
rake (10.0.3)
|
58
|
+
ripl (0.7.0)
|
59
|
+
bond (~> 0.4.2)
|
60
|
+
rspec (2.12.0)
|
61
|
+
rspec-core (~> 2.12.0)
|
62
|
+
rspec-expectations (~> 2.12.0)
|
63
|
+
rspec-mocks (~> 2.12.0)
|
64
|
+
rspec-core (2.12.2)
|
65
|
+
rspec-expectations (2.12.1)
|
66
|
+
diff-lcs (~> 1.1.3)
|
67
|
+
rspec-mocks (2.12.1)
|
68
|
+
simple_oauth (0.2.0)
|
69
|
+
vcr (2.4.0)
|
70
|
+
webmock (1.9.0)
|
71
|
+
addressable (>= 2.2.7)
|
72
|
+
crack (>= 0.1.7)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
ruby
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
admincredible!
|
79
|
+
mongo_mapper
|
80
|
+
nestful
|
81
|
+
rake
|
82
|
+
ripl
|
83
|
+
roauth!
|
84
|
+
rspec
|
85
|
+
vcr
|
86
|
+
webmock
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
|
9
|
+
if defined?(RSpec)
|
10
|
+
spec_tasks = Dir['spec/*/'].map { |d| File.basename(d) }
|
11
|
+
|
12
|
+
spec_tasks.each do |folder|
|
13
|
+
RSpec::Core::RakeTask.new("spec:#{folder}") do |t|
|
14
|
+
t.pattern = "./spec/#{folder}/**/*_spec.rb"
|
15
|
+
t.rspec_opts = %w(-fs --color)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Run complete application spec suite'
|
20
|
+
task 'spec' => spec_tasks.map { |f| "spec:#{f}" }
|
21
|
+
|
22
|
+
desc 'Default: run specs.'
|
23
|
+
task :default => 'spec'
|
24
|
+
end
|
data/Readme.md
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# A brief explanation of the purposes of this so called "gem"
|
2
|
+
|
3
|
+
This gem is for communicating with Joomla! sites running
|
4
|
+
[com_admincredible](https://github.com/Admincredible/com_admincredible) a powerful REST API component. We use both the
|
5
|
+
component and this gem to deliver an incredible service for updating and managing your Joomla sites. Feel free to check
|
6
|
+
it out at [admincredible.com](http://admincredible.com).
|
7
|
+
|
8
|
+
Now that we have got that out of the way let's move onto to how to use this useful thing of a gem.
|
9
|
+
|
10
|
+
# How to for geniuses
|
11
|
+
|
12
|
+
It's been scientifically proven in controlled studies that the smarter you are the more documentation you'll read.
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
You can install using any of the typical methods
|
16
|
+
|
17
|
+
### Rubygems
|
18
|
+
|
19
|
+
Just do the classic
|
20
|
+
|
21
|
+
```sh
|
22
|
+
gem install admincredible
|
23
|
+
```
|
24
|
+
|
25
|
+
### Bundler
|
26
|
+
|
27
|
+
Or add it to to your Gemfile
|
28
|
+
|
29
|
+
gem 'admincredible'
|
30
|
+
|
31
|
+
## Getting things done
|
32
|
+
|
33
|
+
Our gem runs on the very powerful and flexible [faraday](https://github.com/lostisland/faraday) which means our developer can ignore the hard stuff (*1) focus on providing a mind blowing API (*2). It looks like this.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'admincredible'
|
37
|
+
require 'simple_oauth'
|
38
|
+
|
39
|
+
client = Admincredible::Client.new do |config|
|
40
|
+
## The url to the site you're using
|
41
|
+
config.url = 'http://localhost/joomla_old_testsite_257'
|
42
|
+
|
43
|
+
## An OAuth callback to use during generation of an authorization URL. Optional
|
44
|
+
config.oauth_callback = 'http://google.com'
|
45
|
+
|
46
|
+
## OAuth Keys. Optional
|
47
|
+
config.consumer_key = 'foobarcatsdogs1232442'
|
48
|
+
config.consumer_secret = 'foobarcatsdogs1232442'
|
49
|
+
config.token = 'foobarcatsdogs1232442fish'
|
50
|
+
config.token_secret = 'foobarcatsdogs1232442dish'
|
51
|
+
end
|
52
|
+
```
|
53
|
+
1. I hate OAuth. Also, I hate OAuth.
|
54
|
+
2. Admincredble is not responsible for any minds overloaded by the sheer awesomeness of our gem.
|
55
|
+
|
56
|
+
## But wait, I don't have any OAuth keys?
|
57
|
+
|
58
|
+
The gem is here to help with an OAuth resource.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
# Require these.
|
62
|
+
# Why two oauth libs? Because I had to use my own fork of roauth to sign authorization url's :(
|
63
|
+
# I'll fork simple_oauth soon and add the needed feature for signing urls.
|
64
|
+
require 'simple_oauth'
|
65
|
+
require 'roauth'
|
66
|
+
require 'nestful'
|
67
|
+
|
68
|
+
client = Admincredible::Client.new do |config|
|
69
|
+
## The url to the site you're using
|
70
|
+
config.url = 'http://localhost/joomla_old_testsite_257'
|
71
|
+
|
72
|
+
## An OAuth callback to use during generation of an authorization URL. Optional
|
73
|
+
config.oauth_callback = 'http://google.com'
|
74
|
+
end
|
75
|
+
|
76
|
+
client.oauth.register # Register
|
77
|
+
client.oauth.request_token # Get request token
|
78
|
+
client.oauth.authorization_url # Redirect your user to this
|
79
|
+
|
80
|
+
# After the authorization redirect com_admincredible will post the verification to your callback URL.
|
81
|
+
client.oauth.access_token params[:oauth_verifier]
|
82
|
+
```
|
83
|
+
|
84
|
+
That is it. Good luck on your journey into admincredible land.
|
85
|
+
|
86
|
+
# Usage Tips. The stress and tension headache prevention section
|
87
|
+
|
88
|
+
Usage tips are important for those power users that like to push the limits of what is possible
|
89
|
+
and in the process push the limits of their tolerance for frustration.
|
90
|
+
|
91
|
+
## Gotchas
|
92
|
+
|
93
|
+
### Updating Extension
|
94
|
+
|
95
|
+
Extensions in Joomla! don't like to update if they exceed PHP execution limits, the only way around this is to keep
|
96
|
+
trying until they do. Sometimes a Joomla extension will even decide to finish an update in the background. This means
|
97
|
+
that sometimes the gem will return update details and other times it will simply return `{"status"=>200,
|
98
|
+
"data"=>{"success"=>true}, "message"=>"Nothing To Update"}`.
|
99
|
+
|
100
|
+
That means it's up to you to keep track of what extensions you requested updates for and to figure out if they failed or
|
101
|
+
succeeded by calling `client.extensions.all` after calling updates.
|
102
|
+
|
103
|
+
If you keep track of what extensions need updating by first calling `client.extensions.all` you can work around the
|
104
|
+
problem. I know you can, because I did. I cant give you the solution though, it's part of the secret brew that makes up
|
105
|
+
our app.
|
106
|
+
|
107
|
+
## Other Tips
|
108
|
+
|
109
|
+
1. Carry a towel
|
110
|
+
2. Always know where your towel is
|
111
|
+
|
112
|
+
# Development
|
113
|
+
|
114
|
+
## Running Tests
|
115
|
+
|
116
|
+
`$ bundle exec rake spec` should handle everything. It's all fixtured :). If you'd like to run tests live you can setup
|
117
|
+
a site to run at `http://localhost/joomla_old_testsite_257` and set it's authenticator to `debug`
|
118
|
+
|
119
|
+
# License
|
120
|
+
|
121
|
+
GPL V3
|
data/TODOS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
- fix usage of two oauth libraries
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.required_ruby_version = '>= 1.8.7'
|
3
|
+
s.required_rubygems_version = '>= 1.3.6'
|
4
|
+
|
5
|
+
# Details
|
6
|
+
s.name = 'admincredible'
|
7
|
+
s.version = '0.0.1'
|
8
|
+
s.authors = ['Ken Erickson"']
|
9
|
+
s.date = '2013-01-19'
|
10
|
+
s.summary = 'Communicates with com_admincredible, a Joomla! extension that adds REST like APIs to Joomla installs'
|
11
|
+
s.description = 'Communicates with com_admincredible, a Joomla! extension that adds REST like APIs to Joomla installs'
|
12
|
+
s.email = 'bookworm.productions@gmail.com'
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.homepage = 'http://admincredible.com'
|
16
|
+
s.require_paths = ['lib']
|
17
|
+
|
18
|
+
# Dependencies
|
19
|
+
s.add_runtime_dependency 'active_support'
|
20
|
+
s.add_runtime_dependency 'simple_oauth'
|
21
|
+
s.add_runtime_dependency 'faraday', '>= 0.8.0'
|
22
|
+
s.add_runtime_dependency 'faraday_middleware', '>= 0.8.7'
|
23
|
+
s.add_runtime_dependency 'hashie'
|
24
|
+
s.add_runtime_dependency 'inflection'
|
25
|
+
s.add_runtime_dependency 'json'
|
26
|
+
s.add_runtime_dependency 'mime-types'
|
27
|
+
s.add_runtime_dependency 'multipart-post'
|
28
|
+
|
29
|
+
# Development Dependencies
|
30
|
+
s.add_development_dependency 'rake'
|
31
|
+
s.add_development_dependency 'vcr'
|
32
|
+
s.add_development_dependency 'rspec'
|
33
|
+
s.add_development_dependency 'mongo_mapper'
|
34
|
+
s.add_development_dependency 'webmock'
|
35
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'admincredible/client'
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext/string'
|
5
|
+
require 'admincredible/core_ext/string'
|
6
|
+
|
7
|
+
require 'admincredible/configuration'
|
8
|
+
require 'admincredible/connection'
|
9
|
+
require 'admincredible/request'
|
10
|
+
require 'admincredible/joomla_request'
|
11
|
+
require 'admincredible/resource'
|
12
|
+
|
13
|
+
Dir[File.dirname(__FILE__) + '/resources/*.rb'].each { |file| require file }
|
14
|
+
Dir[File.dirname(__FILE__) + '/middleware/*.rb'].each { |file| require file }
|
15
|
+
|
16
|
+
module Admincredible
|
17
|
+
class Client
|
18
|
+
include Connection
|
19
|
+
include Request
|
20
|
+
include JoomlaRequest
|
21
|
+
attr_reader :config
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
raise ArgumentError, 'block not given' unless block_given?
|
25
|
+
|
26
|
+
@config = Admincredible::Configuration.new
|
27
|
+
yield config
|
28
|
+
|
29
|
+
@resource_cache = {}
|
30
|
+
|
31
|
+
if config.logger.nil? || config.logger == true
|
32
|
+
require 'logger'
|
33
|
+
config.logger = Logger.new($stderr)
|
34
|
+
config.logger.level = Logger::WARN
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# A user tries a missing method on our client, we assume it's a resource class and look it up in
|
40
|
+
# Admincredible::Resources. For example, calling client.extensions.all, becomes
|
41
|
+
# Admincredible::Resources::Extension.new().all
|
42
|
+
#
|
43
|
+
# Instances are cached, so this can be said to be sorta implementing that fancy schmancy singleton pattern
|
44
|
+
# all those cool developers are using.
|
45
|
+
#
|
46
|
+
def method_missing(method, *args, &block)
|
47
|
+
method = method.to_s
|
48
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
49
|
+
|
50
|
+
@resource_cache[method] ||= {}
|
51
|
+
|
52
|
+
if !options[:reload] && (cached = @resource_cache[method][options.hash])
|
53
|
+
cached
|
54
|
+
else
|
55
|
+
resource_class = Admincredible::Resources.const_get(method.singularize.modulize)
|
56
|
+
@resource_cache[method][options.hash] = resource_class.new(self, options)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module Admincredible
|
2
|
+
class Configuration
|
3
|
+
# URL + Path Options
|
4
|
+
|
5
|
+
##
|
6
|
+
# @return [String] Required. URL of site.
|
7
|
+
#
|
8
|
+
attr_accessor :url
|
9
|
+
|
10
|
+
##
|
11
|
+
# @return [String] Optional. The direct endpoint to the component.
|
12
|
+
# Defaults to '/components/com_admincredible/direct.php'
|
13
|
+
#
|
14
|
+
attr_accessor :direct_endpoint
|
15
|
+
|
16
|
+
##
|
17
|
+
# @return [String] Optional. The main endpoint (frontend) for the component.
|
18
|
+
# Defaults to '/index.php?option=com_admincredible&view=authorize'
|
19
|
+
attr_accessor :main_endpoint
|
20
|
+
|
21
|
+
##
|
22
|
+
# @return [Symbol] Optional. The authenticator type to use. Not used right now but here for future flexibility
|
23
|
+
# When using gem you should set it just be safe. Defaults to :debug
|
24
|
+
#
|
25
|
+
attr_accessor :authenticator
|
26
|
+
|
27
|
+
# Oauth Options
|
28
|
+
|
29
|
+
##
|
30
|
+
# @return [String] Optional. OAuth Consumer Key.
|
31
|
+
#
|
32
|
+
attr_accessor :consumer_key
|
33
|
+
|
34
|
+
##
|
35
|
+
# @return [String] Optional. OAuth Consumer Secret.
|
36
|
+
#
|
37
|
+
attr_accessor :consumer_secret
|
38
|
+
|
39
|
+
##
|
40
|
+
# @return [String] Optional. OAuth Token.
|
41
|
+
#
|
42
|
+
attr_accessor :token
|
43
|
+
|
44
|
+
##
|
45
|
+
# @return [String] Optional. OAuth Token Secret.
|
46
|
+
#
|
47
|
+
attr_accessor :token_secret
|
48
|
+
|
49
|
+
##
|
50
|
+
# @return [String] Optional. OAuth callback URL.
|
51
|
+
attr_accessor :oauth_callback
|
52
|
+
|
53
|
+
# Faraday options
|
54
|
+
|
55
|
+
##
|
56
|
+
# @return [Hash] Optionals. Options to pass to Faraday
|
57
|
+
attr_accessor :connection_options
|
58
|
+
|
59
|
+
##
|
60
|
+
# @return [Mixed] Optional. Faraday adapter
|
61
|
+
#
|
62
|
+
attr_accessor :adapter
|
63
|
+
|
64
|
+
# Misc Options
|
65
|
+
|
66
|
+
##
|
67
|
+
# @return [Integer] Optional. How quickly do we step an Akeeba restoration script? Defaults to 1 second.
|
68
|
+
attr_accessor :step_after_seconds
|
69
|
+
|
70
|
+
##
|
71
|
+
# @return [Logger] Optional. An instance of an Logger or can be set to true to enable default logger
|
72
|
+
#
|
73
|
+
attr_accessor :logger
|
74
|
+
|
75
|
+
def initialize
|
76
|
+
@connection_options = {}
|
77
|
+
@direct_endpoint = '/components/com_admincredible/direct.php'
|
78
|
+
@main_endpoint = '/index.php?option=com_admincredible&view=authorize'
|
79
|
+
@step_after_seconds = 1
|
80
|
+
end
|
81
|
+
|
82
|
+
def oauth?
|
83
|
+
return true if @consumer_secret || @authenticator == :oauth
|
84
|
+
end
|
85
|
+
|
86
|
+
def url=(url)
|
87
|
+
@url = url.gsub(@direct_endpoint, '')
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Returns the url with the endpoint
|
92
|
+
#
|
93
|
+
# @return [String]
|
94
|
+
def url
|
95
|
+
return @url + @direct_endpoint
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# Returns the raw url that was set during configuration of the client
|
100
|
+
#
|
101
|
+
# @return [String]
|
102
|
+
def raw_url
|
103
|
+
return @url
|
104
|
+
end
|
105
|
+
|
106
|
+
def oauth_options
|
107
|
+
return {
|
108
|
+
:consumer_key => @consumer_key,
|
109
|
+
:consumer_secret => @consumer_secret,
|
110
|
+
:token => @token,
|
111
|
+
:token_secret => @token_secret
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
def connection_options
|
116
|
+
{
|
117
|
+
:headers => {
|
118
|
+
:accept => 'application/json',
|
119
|
+
:user_agent => 'Admincredible Ruby Gem'
|
120
|
+
},
|
121
|
+
:url => url
|
122
|
+
}.merge(@connection_options)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|