Skip to content

Commit 08b7794

Browse files
committed
Initial commit of the new gooddata-ruby
1 parent 3af3e72 commit 08b7794

15 files changed

+850
-0
lines changed

.document

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
README.rdoc
2+
lib/**/*.rb
3+
bin/*
4+
features/**/*.feature
5+
LICENSE

.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## MAC OS
2+
.DS_Store
3+
4+
## TEXTMATE
5+
*.tmproj
6+
tmtags
7+
8+
## EMACS
9+
*~
10+
\#*
11+
.\#*
12+
13+
## VIM
14+
*.swp
15+
16+
## PROJECT::GENERAL
17+
coverage
18+
rdoc
19+
pkg
20+
21+
## PROJECT::SPECIFIC

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(BSD License)
2+
3+
Copyright (c) 2010 Thomas Watson Steen & GoodData Corporation. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification, are permitted provided
6+
that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright notice, this list of conditions and
9+
the following disclaimer.
10+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11+
and the following disclaimer in the documentation and/or other materials provided with the distribution.
12+
* Neither the name of the GoodData Corporation nor the names of its contributors may be used to endorse
13+
or promote products derived from this software without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
16+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17+
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.rdoc

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
= GoodData Ruby wrapper and CLI
2+
3+
A convenient Ruby wrapper around the GoodData RESTful API.
4+
5+
This is a two-in one tool. It both contains a wrapper class called GoodData::Base
6+
that you can use in your own projects and a CLI for use on the prompt.
7+
8+
The best documentation for the API can be found using these resources:
9+
* http://developer.gooddata.com/api
10+
* https://secure.gooddata.com/gdc
11+
12+
== Usage
13+
14+
Install gooddata-ruby gem
15+
16+
gem install gooddata-ruby
17+
18+
Now you are ready to use either the Ruby wrapper class or the CLI.
19+
20+
=== Wrapper class usage
21+
22+
For details of how to use the Ruby wrapper class, see the GoodData::Base RDoc.
23+
24+
=== CLI Usage
25+
26+
After installing the gooddata-ruby gem, GoodData is available from your command line using
27+
the <tt>gdr</tt> command. To get a complete overview of possible options type:
28+
29+
gdr --help
30+
31+
The examples and descriptions below does not cover all the options available via the CLI.
32+
So remember to refer back to the <tt>--help</tt> mode.
33+
34+
Before you do anything else, a good idea is to see if your account is set up correctly and
35+
that you can log in. To do this, use the test-mode:
36+
37+
gdr --test
38+
39+
==== Authentication
40+
41+
As you saw if you ran the above test command <tt>gdr</tt> will prompt you for your GoodData username
42+
and password. Alternatively you can also specify it using the command line options <tt>--username</tt>
43+
/ <tt>-u</tt> and <tt>--password</tt> / <tt>-p</tt>. Examples:
44+
45+
$ gdr -u user@example.com
46+
Password:
47+
48+
$ gdr -u user@example.com -p secret
49+
50+
In the latter example the password is written in clear-text in the console. This is not recommended.
51+
Alternatively the first method can be used.
52+
53+
If you don't wish to write your credentials each time you connect to GoodData using <tt>gdr</tt>, you can
54+
create a simple gdr settings file called <tt>.gdr</tt> in the root of your users home directory. To make it
55+
easy you can just run the settings file generator command which will create the file for you:
56+
57+
gdr --write-settings
58+
59+
==== List available projects
60+
61+
To get a list of projects available to your GoodData user account, run:
62+
63+
gdr -l
64+
65+
The output from the above command will look similar to this:
66+
67+
521 Some project
68+
3521 Some other project
69+
3642 Some third project
70+
71+
The first column contains the project-id. You need this if you wan't to either see more details about
72+
the project using the <tt>--show-project</tt> mode or if you wish to delete the project using the
73+
<tt>--delete-project</tt> mode.
74+
75+
==== Create a new project
76+
77+
To create a new project under on the GoodData servers, run:
78+
79+
gdr -c
80+
81+
You will then be asked about the desired project name and summary before it's created.
82+
83+
== Note on Patches/Pull Requests
84+
85+
* Fork the project.
86+
* Make your feature addition or bug fix.
87+
* Add tests for it. This is important so I don't break it in a
88+
future version unintentionally.
89+
* Commit, do not mess with rakefile, version, or history.
90+
(if you want to have your own version, that is fine but bump version in a commit by itself we can ignore when we pull)
91+
* Send us a pull request. Bonus points for topic branches.
92+
93+
== Credits
94+
95+
This project is developed and maintained by Thomas Watson Steen [ mailto:w@tson.dk / {@wa7son}[http://twitter.com/wa7son] ]
96+
97+
== Copyright
98+
99+
Copyright (c) 2010 Thomas Watson Steen & GoodData Corporation. See LICENSE for details.

Rakefile

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
require 'rubygems'
2+
require 'rake'
3+
4+
begin
5+
require 'jeweler'
6+
Jeweler::Tasks.new do |gem|
7+
gem.name = "GoodData Ruby wrapper and CLI"
8+
gem.summary = %Q{A convenient Ruby wrapper around the GoodData RESTful API}
9+
gem.description = %Q{This is a two-in one tool. It both contains a wrapper class called GoodData::Base that you can use in your own projects and a CLI for use on the prompt.}
10+
gem.email = "w@tson.dk"
11+
gem.homepage = "http://github.com/gooddata/gooddata-ruby"
12+
gem.authors = ["Thomas Watson Steen"]
13+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14+
gem.add_dependency 'parseconfig'
15+
gem.add_dependency 'json'
16+
gem.add_dependency 'rest-client'
17+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18+
end
19+
Jeweler::GemcutterTasks.new
20+
rescue LoadError
21+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22+
end
23+
24+
require 'rake/testtask'
25+
Rake::TestTask.new(:test) do |test|
26+
test.libs << 'lib' << 'test'
27+
test.pattern = 'test/**/test_*.rb'
28+
test.verbose = true
29+
end
30+
31+
begin
32+
require 'rcov/rcovtask'
33+
Rcov::RcovTask.new do |test|
34+
test.libs << 'test'
35+
test.pattern = 'test/**/test_*.rb'
36+
test.verbose = true
37+
end
38+
rescue LoadError
39+
task :rcov do
40+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41+
end
42+
end
43+
44+
task :test => :check_dependencies
45+
46+
task :default => :test
47+
48+
require 'rake/rdoctask'
49+
Rake::RDocTask.new do |rdoc|
50+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
51+
52+
rdoc.rdoc_dir = 'rdoc'
53+
rdoc.title = "gooddata-ruby #{version}"
54+
rdoc.rdoc_files.include('README*')
55+
rdoc.rdoc_files.include('lib/**/*.rb')
56+
end

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

bin/gdr

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require File.dirname(__FILE__) + '/../lib/good_data_cli'
2+
GoodDataCli.run

lib/good_data/base.rb

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
require 'logger'
2+
Dir[File.dirname(__FILE__) + '/**/*.rb'].each { |file| require file }
3+
4+
# Wrapper module for all GoodData classes. See the Base class for details.
5+
#
6+
# == Logging
7+
#
8+
# The only thing contained directly in this module is logger object used to log all
9+
# activity in the GoodData API wrapper. Before logging, the logger must
10+
# first be initialized using the init_logger method. After initialization,
11+
# an event can be logged using the logger attribute:
12+
#
13+
# GoodData.logger.error 'Something bad happend!'
14+
#
15+
# For details about the logger options and methods, see the
16+
# {Logger module documentation}[http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc].
17+
#
18+
module GoodData
19+
class << self
20+
attr_accessor :logger
21+
22+
# Prepare the Logger object. Logs to STDOUT.
23+
#
24+
# === Parameters
25+
#
26+
# * +level+ - the log level (:fatal, :error, :warn (default), :info, :debug)
27+
def init_logger(level = :warn)
28+
@logger = Logger.new(STDOUT)
29+
@logger.level = eval("Logger::#{level.to_s.upcase}")
30+
end
31+
end
32+
33+
# = GoodData API wrapper
34+
#
35+
# A convenient Ruby wrapper around the GoodData RESTful API.
36+
#
37+
# The best documentation for the API can be found using these resources:
38+
# * http://developer.gooddata.com/api
39+
# * https://secure.gooddata.com/gdc
40+
#
41+
# == Usage
42+
#
43+
# To communicate with the API you first need a personal GoodData account.
44+
# {Sign up here}[https://secure.gooddata.com/registration.html] if you havent already.
45+
#
46+
# Now it is just a matter of creating a new GoodData::Base object:
47+
#
48+
# gd = GoodData::Base.new :username => 'gooddata_username',
49+
# :password => 'gooddata_password'
50+
#
51+
# This GoodData object can now be utalized to retrieve your GoodData profile, the available
52+
# projects etc.
53+
#
54+
class Base
55+
RELEASE_INFO_PATH = '/gdc/releaseInfo'
56+
57+
# Creates a new GoodData API wrapper
58+
#
59+
# === Parameters
60+
#
61+
# * +attributes+ - A Hash of configuration attributes.
62+
#
63+
# ==== Possible attributes:
64+
#
65+
# * :username (required)
66+
# * :password (required)
67+
# * :log_level (defaults to :warn) - see GoodData.init_logger for possible values.
68+
#
69+
# The Hash keys can be both symbols and strings. So :username is just as good as 'username'.
70+
def initialize(attributes)
71+
attributes = attributes.inject({}) { |memo, (k,v)| memo[k.to_sym] = v; memo } # convert all attribute keys to symbols
72+
attributes = { :log_level => :warn }.merge attributes
73+
GoodData.init_logger attributes[:log_level]
74+
Connection.instance.set_credentials attributes[:username], attributes[:password]
75+
end
76+
77+
# Returns the currently logged in user Profile.
78+
def profile
79+
@profile ||= Profile.load
80+
end
81+
82+
# Returns an Array of projects.
83+
#
84+
# The Array is of type GoodData::Collections::Projects and each element is of type GoodData::Project.
85+
def projects
86+
@projects ||= profile.projects
87+
end
88+
89+
# Returns information about the GoodData API as a Hash (e.g. version, release time etc.)
90+
def release_info
91+
@release_info ||= Connection.instance.get(RELEASE_INFO_PATH)['release']
92+
end
93+
end
94+
end

lib/good_data/collections/projects.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module GoodData
2+
module Collections
3+
class Projects < Array
4+
def create(attributes)
5+
GoodData.logger.info "Creating project #{attributes[:name]}"
6+
7+
json = {
8+
'meta' => {
9+
'title' => attributes[:name],
10+
'summary' => attributes[:summary]
11+
},
12+
'content' => {
13+
# 'state' => 'ENABLED',
14+
'guidedNavigation' => 1
15+
}
16+
}
17+
18+
json['mata']['projectTemplate'] = attributes[:template] if attributes.has_key? :template
19+
20+
self << Project.create(json)
21+
last
22+
end
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)