openfire-ruby 0.1.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: 6e1d440cf8eda88d3d1d21000254f2903d619094
4
+ data.tar.gz: 383920fb5dddab5338b6016a33980fd6ea9adde6
5
+ SHA512:
6
+ metadata.gz: 7ea8162d5423ee30a5e7b0d643ef0622d0cd0f9790403708b876fbae4bff7f0ab84a602297df67564c2be69ef6b2581cad57f3310f7e42e9ccb6b506031bf236
7
+ data.tar.gz: 2feb0baa96063f647730053ba545e749fc64c8e60a67ffbbce7e33eeb6d758c4ae35c65efd5ad46f71073391521c1e425dc82debee76db6542070a1bf8130055
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
11
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in openfire-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jan Schwenzien
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Openfire Ruby Client
2
+
3
+ This is a ruby client for the [REST API plugin](http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html
4
+ ) for [Openfire](http://www.igniterealtime.org/projects/openfire/).
5
+
6
+ It is based on [Her](https://github.com/remiprev/her), takes care of the rather unusual JSON/XML reponses of the plugin, and provides Her::Models for the resources.
7
+
8
+ [![Build Status](https://travis-ci.org/GeneralScripting/openfire-ruby.svg)](https://travis-ci.org/GeneralScripting/openfire-ruby)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'openfire-ruby'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install openfire-ruby
25
+
26
+ ## Usage
27
+
28
+ Create a client:
29
+
30
+ client = Openfire::Client.new('http://localhost:9090', 'secrettoken')
31
+
32
+ Access the User service:
33
+
34
+ # find all the users
35
+ client.users.all.to_a
36
+
37
+ # get a specific user
38
+ client.users.find('username')
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/GeneralScripting/openfire-ruby](https://github.com/GeneralScripting/openfire-ruby). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
49
+
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
54
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "openfire/ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,20 @@
1
+ module Faraday
2
+ class Request
3
+ class XML < Faraday::Middleware
4
+ dependency 'active_support/all'
5
+
6
+ def initialize(app, options={})
7
+ @app = app
8
+ @options = options
9
+ end
10
+
11
+ def call(env)
12
+ if env[:method] == :post
13
+ env[:body] = env[:body].to_xml(:root => env[:body].delete(:root))
14
+ end
15
+
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ require 'faraday_middleware/response_middleware'
2
+
3
+ module FaradayMiddleware
4
+ class ParseOpenfireJson < FaradayMiddleware::ResponseMiddleware
5
+
6
+ dependency do
7
+ require 'json' unless defined?(::JSON)
8
+ end
9
+
10
+ define_parser do |body|
11
+ unless body.strip.empty?
12
+ parsed = ::JSON.parse body
13
+ case parsed.keys.length
14
+ when 0
15
+ parsed = []
16
+ when 1
17
+ parsed = parsed.values.first
18
+ end
19
+
20
+ if parsed.is_a?(Hash)
21
+ { data: parsed.symbolize_keys }
22
+ else
23
+ { data: parsed }
24
+ end
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ require 'faraday_middleware/response_middleware'
2
+
3
+ module FaradayMiddleware
4
+ class ParseOpenfireXml < FaradayMiddleware::ResponseMiddleware
5
+
6
+ dependency 'multi_xml'
7
+
8
+ define_parser do |body|
9
+ parsed = ::MultiXml.parse(body)
10
+ root = parsed.keys.first
11
+ if parsed[root].nil?
12
+ parsed[root] = []
13
+ else
14
+ parsed[root] = parsed[root].values.first
15
+ if parsed.keys.length == 1
16
+ parsed[root.to_s.pluralize] = parsed.delete(root)
17
+ end
18
+ end
19
+ if root == "error"
20
+ { errors: [parsed["errors"]], data: {} }
21
+ else
22
+ { data: parsed.symbolize_keys }
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ module Openfire
2
+ class Client
3
+
4
+ attr_accessor :her_client
5
+
6
+ HER_CLIENT = Her::API.new
7
+
8
+ def initialize(url, token, options={})
9
+ url.gsub!(/\/$/,'')
10
+ url = "http://#{url}" unless url.match /^http/
11
+ url = "#{url}/plugins/restapi/v1/"
12
+ headers = {
13
+ 'Authorization' => token,
14
+ 'Content-Type' => 'application/json',
15
+ 'Accept' => 'application/json'
16
+ }
17
+ HER_CLIENT.setup url: url, headers: headers do |c|
18
+ c.request :json
19
+ c.response :openfire_xml, content_type: /\bxml$/
20
+ c.response :openfire_json, content_type: /\bjson$/
21
+ c.use Faraday::Adapter::NetHttp
22
+ end
23
+ end
24
+
25
+ def groups
26
+ @groups ||= Openfire::Ruby::Group
27
+ end
28
+
29
+ def users
30
+ @users ||= Openfire::Ruby::User
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ #require 'faraday'
2
+
3
+ require 'her'
4
+ require 'faraday_middleware'
5
+ #require 'faraday/request/xml'
6
+ require 'faraday_middleware/parse_openfire_xml'
7
+ require 'faraday_middleware/parse_openfire_json'
8
+
9
+ require "openfire/client"
10
+ require "openfire/ruby/base"
11
+ require "openfire/ruby/group"
12
+ require "openfire/ruby/user"
13
+ require "openfire/ruby/version"
14
+
15
+ #Faraday::Request.register_middleware xml: lambda { Faraday::Request::XML }
16
+ Faraday::Response.register_middleware openfire_xml: lambda { FaradayMiddleware::ParseOpenfireXml }
17
+ Faraday::Response.register_middleware openfire_json: lambda { FaradayMiddleware::ParseOpenfireJson }
18
+
19
+ module Openfire
20
+ module Ruby
21
+ # nop
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ module Openfire
2
+ module Ruby
3
+ class Base
4
+
5
+ include Her::Model
6
+ use_api Openfire::Client::HER_CLIENT
7
+ parse_root_in_json true
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # This class should never be used directly in your code.
2
+ # Create an instance of Openfire::Client first and then
3
+ # use client.groups
4
+ module Openfire
5
+ module Ruby
6
+ class Group < Base
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # This class should never be used directly in your code.
2
+ # Create an instance of Openfire::Client first and then
3
+ # use client.users
4
+ module Openfire
5
+ module Ruby
6
+ class User < Base
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Openfire
2
+ module Ruby
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'openfire/ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "openfire-ruby"
8
+ spec.version = Openfire::Ruby::VERSION
9
+ spec.authors = ["Jan Schwenzien"]
10
+ spec.email = ["jan@general-scripting.com"]
11
+
12
+ spec.summary = %q{Ruby client for the REST API plugin of Openfire.}
13
+ spec.description = %q{Ruby client for the REST API plugin of Openfire.}
14
+ spec.homepage = "https://github.com/GeneralScripting/openfire-ruby"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec"
33
+
34
+ spec.add_dependency "her"
35
+ #spec.add_dependency "faraday"
36
+ spec.add_dependency "faraday_middleware"
37
+ spec.add_dependency "multi_xml"
38
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openfire-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jan Schwenzien
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: her
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday_middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: multi_xml
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Ruby client for the REST API plugin of Openfire.
98
+ email:
99
+ - jan@general-scripting.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/faraday/request/xml.rb
115
+ - lib/faraday_middleware/parse_openfire_json.rb
116
+ - lib/faraday_middleware/parse_openfire_xml.rb
117
+ - lib/openfire/client.rb
118
+ - lib/openfire/ruby.rb
119
+ - lib/openfire/ruby/base.rb
120
+ - lib/openfire/ruby/group.rb
121
+ - lib/openfire/ruby/user.rb
122
+ - lib/openfire/ruby/version.rb
123
+ - openfire-ruby.gemspec
124
+ homepage: https://github.com/GeneralScripting/openfire-ruby
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.4.8
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Ruby client for the REST API plugin of Openfire.
148
+ test_files: []