chubas-pbruby 0.0.1

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.
data/LICENSE ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # pbruby - The Peanut Buttered API
2
+
3
+ This is Ruby Wrapper for [pbworks API][1]. Note that PBWorks API is not complete and has incomplete documentation.
4
+
5
+ WIP
6
+
7
+
8
+ [1]: http://pbworks.com/api_v2/
9
+
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "pbruby"
8
+ gem.summary = "Ruby wrapper for PBWorks (formerly PBWiki) API"
9
+ gem.description = "Peanut buttered Ruby! Access the PBWorks API (still in beta) from Ruby"
10
+ gem.email = "ruben.medellin.c@gmail.com"
11
+ gem.homepage = "http://github.com/chubas/pbruby"
12
+ gem.authors = ["Rubén Medellín"]
13
+ end
14
+ rescue LoadError
15
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
16
+ end
17
+
18
+ task :default => :test
19
+ require 'rake/rdoctask'
20
+ Rake::RDocTask.new do |rdoc|
21
+ if File.exist?('VERSION.yml')
22
+ config = YAML.load(File.read('VERSION.yml'))
23
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
24
+ elsif File.exist?('VERSION')
25
+ version = File.read('VERSION')
26
+ else
27
+ version = ""
28
+ end
29
+
30
+ rdoc.rdoc_dir = 'rdoc'
31
+ rdoc.title = "peeping #{version}"
32
+ rdoc.rdoc_files.include('README*')
33
+ rdoc.rdoc_files.include('lib/**/*.rb')
34
+ end
data/TODO ADDED
File without changes
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 0
3
+ :patch: 1
4
+ :major: 0
data/lib/pbruby.rb ADDED
File without changes
@@ -0,0 +1,147 @@
1
+ require 'rubygems'
2
+ require 'mash'
3
+ require 'httparty'
4
+
5
+ module PBWiki
6
+ class Client
7
+
8
+ include HTTParty
9
+
10
+ attr_accessor :name
11
+ attr_accessor :read, :write, :admin
12
+
13
+ def initialize(name, keys = {})
14
+ @name = name
15
+ @read, @write, @admin = keys.values_at(:read, :write, :admin)
16
+ end
17
+
18
+ # Gets the method corresponding to the PBWorks v2 API, with the requested parameters.
19
+ def self.perform_api_request(verb, base_uri, format, secure, api_method, params = {})
20
+ response = send(verb,
21
+ "/api_v2/",
22
+ :base_uri => base_uri,
23
+ :query => {
24
+ :op => api_method,
25
+ :_type => 'jsontext'}.merge(params))
26
+ response = response.gsub(/^\/\*-secure-/, '').gsub(/\*\/$/, '').strip if secure
27
+ format == :json ? Mash.new(Crack::JSON.parse(response)) : response
28
+ rescue Crack::ParseError
29
+ raise "Malformed json response"
30
+ end
31
+
32
+ def request(verb, http_method, format, api_method, params, secure = true)
33
+ uri_prefix = http_method == :https ? 'https' : 'http'
34
+ uri = "#{uri_prefix}://#{@name}.pbworks.com/"
35
+
36
+ self.class.perform_api_request(verb, uri, format, secure, api_method, params)
37
+ end
38
+
39
+ class << self
40
+ alias old_method_missing method_missing
41
+ def method_missing(name, *args, &blk)
42
+ if name.to_s =~ /^pb_([a-z]+_)*(read|write|admin)$/
43
+
44
+ raise "A method name must be defined" unless args.size >= 1
45
+ raise "An API operation method name should be defined" unless args.size >= 2
46
+
47
+ s_method_name = name.to_s.split('_')
48
+ def_parameters = s_method_name[1...-1] # Get the method words between
49
+ action_key = s_method_name.last
50
+ method_name = args.shift
51
+ api_method_name = args.shift
52
+ required_keys = args
53
+
54
+ define_method(method_name) do |*api_method_params_optional_args|
55
+ api_method_params = api_method_params_optional_args[0] || {}
56
+ unless required_keys.all?{|key| api_method_params.keys.include?(key)}
57
+ raise "Error. Api method requires the following keys: #{args.inspect}"
58
+ end
59
+ verb = def_parameters.include?('post') ? :post : :get
60
+ http_method = def_parameters.include?('https') ? :https : :http
61
+ format = def_parameters.include?('plain') ? :plain : :json
62
+ secure = def_parameters.include?('basic') ? false : true
63
+ api_method_params.merge!("#{action_key}_key".to_sym => instance_variable_get("@#{action_key}"))
64
+ request(verb, http_method, format, api_method_name, api_method_params, secure)
65
+ end
66
+ else
67
+ old_method_missing(name, *args, &blk)
68
+ end
69
+ end
70
+ end
71
+
72
+ pb_read :bundle, 'GetBundle'
73
+
74
+ pb_read :changes, 'GetChanges'
75
+
76
+ pb_https_post_admin :delete_file, 'DeleteFile', :file # **
77
+ pb_plain_admin :file, 'GetFile', :filename
78
+ pb_read :file_revisions, 'GetFileRevisions'
79
+ pb_admin :files, 'GetFiles'
80
+ pb_admin :storage, 'GetStorageInfo'
81
+ pb_https_post_admin :put_file, 'PutFile', :data # **
82
+ pb_https_post_admin :rename_file, 'RenameFile', :from, :to
83
+ pb_https_post_admin :revert_file, 'RevertFile', :file, :revision
84
+
85
+ pb_https_post_admin :create_folder, 'CreateFolder', :folder
86
+ pb_https_post_admin :delete_folder, 'DeleteFolder', :folder
87
+ pb_read :file_folder, 'GetFileFolder', :file
88
+ pb_read :folder_objects, 'GetFolderObjects', :folder
89
+ pb_read :page_folder, 'GetPageFolder', :page
90
+ pb_admin :folders, 'GetFolders'
91
+ pb_admin :file_folders, 'GetFileFolders'
92
+ pb_https_post_admin :rename_folder, 'RenameFolder', :folder, :to # **
93
+ pb_https_post_admin :set_file_folder, 'SetFileFolder', :file
94
+ pb_https_post_admin :set_page_folder, 'SetPageFolder', :page
95
+
96
+ pb_admin :create_user, 'CreateUser', :user, :password
97
+ pb_admin :create_wiki, 'CreateWiki', :tz, :wiki, :cat
98
+ pb_admin :index, 'Index'
99
+ pb_admin :multi, 'Multi', :calls
100
+ pb_read :render, 'RenderContent', :text
101
+
102
+ pb_read :templates, 'GetTemplates'
103
+ pb_read :times, 'GetTimes'
104
+
105
+ pb_admin :network_users, 'GetNewtorkUsers', :anchor, :count, :filter, :offset, :sortby, :reverse, :verbose, :perm, :pending
106
+
107
+ pb_admin :objects, 'GetObjects', :folder
108
+ pb_admin :ops, 'GetOps'
109
+ pb_admin :help, 'Help', :help
110
+ pb_admin :is_hiring, 'IsHiringEngineers'
111
+ pb_read :pagebase, 'PageBase'
112
+ pb_admin :ping, 'Ping'
113
+
114
+ pb_https_post_write :append_page, 'AppendPage', :page, :html
115
+ pb_https_post_write :create_page, 'CreatePage', :page
116
+ pb_write :delete_autosave, 'DeleteAutosave', :page
117
+ pb_https_post_admin :delete_page, 'DeletePage', :page
118
+
119
+ pb_admin :page, 'GetPage', :page
120
+ pb_admin :page_lock, 'GetPageLock', :page
121
+ pb_admin :page_security, 'GetPageSecurity', :page
122
+ pb_read :pages, 'GetPages'
123
+ pb_read :search, 'Search', :q
124
+
125
+ pb_admin :folder_security, 'GetFolderSecurity', :folder
126
+
127
+ pb_read :page_tags, 'GetPageTags', :page
128
+ pb_read :tag_pages, 'GetTagPages', :tag
129
+ pb_read :tags, 'GetTags'
130
+
131
+ pb_read :milestone, 'GetMilestone', :milestone_id
132
+ pb_read :milestones, 'GetMilestones'
133
+ pb_read :task, 'GetTask', :task_id
134
+ pb_read :task_events, 'GetTaskEvents', :task_id
135
+ pb_read :tasks, 'GetTasks'
136
+
137
+ pb_read :user, 'GetUserInfo'
138
+ pb_read :user_pref, 'GetUserPref', :key
139
+ pb_read :user_prefs, 'GetUserPrefs', :keys
140
+ pb_admin :users, 'GetUsersInfos'
141
+
142
+ pb_admin :upgrade_info, 'GetUpgradeInfo', :wiki
143
+ pb_admin :leave, 'LeaveWorkspace', :wiki
144
+
145
+ end
146
+ end
147
+
@@ -0,0 +1 @@
1
+
data/pbruby.gemspec ADDED
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{pbruby}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Rub\303\251n Medell\303\255n"]
9
+ s.date = %q{2009-08-26}
10
+ s.description = %q{Peanut buttered Ruby! Access the PBWorks API (still in beta) from Ruby}
11
+ s.email = %q{ruben.medellin.c@gmail.com}
12
+ s.extra_rdoc_files = [
13
+ "LICENSE",
14
+ "README.md"
15
+ ]
16
+ s.files = [
17
+ "LICENSE",
18
+ "README.md",
19
+ "Rakefile",
20
+ "TODO",
21
+ "VERSION.yml",
22
+ "lib/pbruby.rb",
23
+ "lib/pbruby/client.rb",
24
+ "lib/pbruby/pb_methods.rb",
25
+ "pbruby.gemspec",
26
+ "setup.rb"
27
+ ]
28
+ s.has_rdoc = true
29
+ s.homepage = %q{http://github.com/chubas/pbruby}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.2}
33
+ s.summary = %q{Ruby wrapper for PBWorks (formerly PBWiki) API}
34
+
35
+ if s.respond_to? :specification_version then
36
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
40
+ else
41
+ end
42
+ else
43
+ end
44
+ end
data/setup.rb ADDED
File without changes
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chubas-pbruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "Rub\xC3\xA9n Medell\xC3\xADn"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-26 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Peanut buttered Ruby! Access the PBWorks API (still in beta) from Ruby
17
+ email: ruben.medellin.c@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.md
25
+ files:
26
+ - LICENSE
27
+ - README.md
28
+ - Rakefile
29
+ - TODO
30
+ - VERSION.yml
31
+ - lib/pbruby.rb
32
+ - lib/pbruby/client.rb
33
+ - lib/pbruby/pb_methods.rb
34
+ - pbruby.gemspec
35
+ - setup.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/chubas/pbruby
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Ruby wrapper for PBWorks (formerly PBWiki) API
62
+ test_files: []
63
+