iformat 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.
Files changed (43) hide show
  1. data/.gitignore +17 -0
  2. data/.travis.yml +7 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +22 -0
  5. data/README.md +34 -0
  6. data/Rakefile +11 -0
  7. data/iformat.gemspec +23 -0
  8. data/lib/iformat/base.rb +42 -0
  9. data/lib/iformat/category.rb +24 -0
  10. data/lib/iformat/client/orders.rb +43 -0
  11. data/lib/iformat/client/products.rb +31 -0
  12. data/lib/iformat/client/session.rb +22 -0
  13. data/lib/iformat/client.rb +73 -0
  14. data/lib/iformat/configuration.rb +47 -0
  15. data/lib/iformat/error/authorization_error.rb +8 -0
  16. data/lib/iformat/error/bad_session_id.rb +8 -0
  17. data/lib/iformat/error/bad_username_or_password.rb +8 -0
  18. data/lib/iformat/error/bad_username_or_password_or_passwords_different.rb +8 -0
  19. data/lib/iformat/error/client_error.rb +8 -0
  20. data/lib/iformat/error/header_error.rb +8 -0
  21. data/lib/iformat/error/insert_coin.rb +8 -0
  22. data/lib/iformat/error/internal_error.rb +8 -0
  23. data/lib/iformat/error/item_error.rb +8 -0
  24. data/lib/iformat/error/logo_error.rb +8 -0
  25. data/lib/iformat/error/not_all_lines_have_links.rb +8 -0
  26. data/lib/iformat/error/order_already_exists.rb +8 -0
  27. data/lib/iformat/error/order_closed_no_links_generated.rb +8 -0
  28. data/lib/iformat/error/order_deleted_from_system.rb +8 -0
  29. data/lib/iformat/error/order_not_found.rb +8 -0
  30. data/lib/iformat/error/order_waiting_for_links.rb +8 -0
  31. data/lib/iformat/error/result_too_big.rb +8 -0
  32. data/lib/iformat/error/server_error.rb +8 -0
  33. data/lib/iformat/error/unknown_error.rb +8 -0
  34. data/lib/iformat/error.rb +31 -0
  35. data/lib/iformat/order.rb +24 -0
  36. data/lib/iformat/order_item.rb +20 -0
  37. data/lib/iformat/session.rb +20 -0
  38. data/lib/iformat/version.rb +3 -0
  39. data/lib/iformat.rb +35 -0
  40. data/test/helper.rb +4 -0
  41. data/test/test_client.rb +55 -0
  42. data/test/test_iformat.rb +53 -0
  43. metadata +169 -0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby
6
+ - rbx
7
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in iformat.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Karol Sarnacki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # The iFormat Ruby Gem [![Build Status](https://secure.travis-ci.org/sodercober/iformat.png?branch=master)][travis] [![Dependency Status](https://gemnasium.com/sodercober/iformat.png?travis)][gemnasium]
2
+ A Ruby wrapper for the [iFormat](http://www.iformat.pl/) API.
3
+
4
+ [iFormat](http://www.iformat.pl/) is a digital platform for publishers of electronic publications that offers digitalisation, conversion, file security and electronic distribution.
5
+
6
+ [travis]: http://travis-ci.org/sodercober/iformat
7
+ [gemnasium]: https://gemnasium.com/sodercober/iformat
8
+
9
+
10
+ ## <a name="installation"></a>Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'iformat'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install iformat
23
+
24
+ ## <a name="usage"></a>Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## <a name="contributing"></a>Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/test_*.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
data/iformat.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/iformat/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['Karol Sarnacki']
6
+ gem.email = ['sodercober@gmail.com']
7
+ gem.description = %q{A Ruby wrapper for the iFormat API.}
8
+ gem.summary = %q{iFormat API wrapper}
9
+ gem.homepage = 'https://github.com/sodercober/iformat'
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = 'iformat'
15
+ gem.require_paths = ['lib']
16
+ gem.version = IFormat::VERSION
17
+
18
+ gem.add_runtime_dependency 'savon', ['~> 0.9']
19
+
20
+ gem.add_development_dependency 'minitest', ['>= 2.0.0']
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'turn'
23
+ end
@@ -0,0 +1,42 @@
1
+ module IFormat
2
+
3
+ class Base
4
+ attr_accessor :attrs
5
+ alias :to_hash :attrs
6
+
7
+ # Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
8
+ #
9
+ # @overload self.lazy_attr_reader(attr)
10
+ # @param attr [Symbol]
11
+ # @overload self.lazy_attr_reader(attrs)
12
+ # @param attrs [Array<Symbol>]
13
+ def self.lazy_attr_reader(*attrs)
14
+ attrs.each do |attribute|
15
+ class_eval do
16
+ define_method attribute do
17
+ @attrs[attribute]
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ # Initializes a new Base object
24
+ #
25
+ # @param attrs [Hash]
26
+ # @return [IFormat::Base]
27
+ def initialize(attrs = {})
28
+ @attrs = attrs.dup
29
+ end
30
+
31
+ # Initializes a new Base object
32
+ #
33
+ # @param method [String, Symbol] Message to send to the object
34
+ def [](method)
35
+ self.__send__(method.to_sym)
36
+ rescue NoMethodError
37
+ nil
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,24 @@
1
+ require 'iformat/base'
2
+
3
+ module IFormat
4
+
5
+ class Category < IFormat::Base
6
+ lazy_attr_reader :url, :catid, :mtime, :title
7
+
8
+ def id
9
+ @id ||= @attrs[:catid].to_i
10
+ end
11
+
12
+ def updated_at
13
+ @updated_at ||= @attrs[:mtime]
14
+ end
15
+
16
+ # @param other [IFormat::Category]
17
+ # @return [Boolean]
18
+ def ==(other)
19
+ super || (other.class == self.class && other.id == self.id)
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,43 @@
1
+ module IFormat
2
+
3
+ class Client
4
+
5
+ module Orders
6
+
7
+ def create_order(id, items)
8
+ attrs = session_request(:create_order, {
9
+ 'orderID' => id,
10
+ 'items' => {
11
+ 'iFSCreateOrderReq' => items.map(&:to_hash)
12
+ }
13
+ })
14
+ end
15
+
16
+ def get_order_info(id)
17
+ attrs = session_request(:get_order_info, {
18
+ 'orderID' => id
19
+ })
20
+ end
21
+
22
+ def repeat_order
23
+ raise NotImplementedError
24
+ end
25
+
26
+ def get_orders_history(start = 0, limit = 5)
27
+ attrs = session_request(:get_orders_history, {
28
+ 'start' => start,
29
+ 'limit' => limit
30
+ })
31
+ end
32
+
33
+ def get_orders_history_quantity
34
+ attrs = session_request(:get_orders_history_quantity)
35
+
36
+ attrs[:quantity].to_i
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,31 @@
1
+ require 'iformat/category'
2
+
3
+ module IFormat
4
+
5
+ class Client
6
+
7
+ module Products
8
+
9
+ def get_products
10
+ products_attrs = session_request(:get_products)
11
+
12
+ products_attrs[:products_n][:i_fs_product].map do |attrs|
13
+ IFormat::Category.new(attrs)
14
+ end
15
+ end
16
+
17
+ def get_items_history(since)
18
+ since = since.xmlschema if since.respond_to?(:xmlschema)
19
+
20
+ attrs = session_request(:get_items_history, {
21
+ :date => since
22
+ })
23
+
24
+ attrs[:result]
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,22 @@
1
+ require 'iformat/session'
2
+
3
+ module IFormat
4
+
5
+ class Client
6
+
7
+ module Session
8
+
9
+ def get_session
10
+ attrs = request(:get_session, {
11
+ :username => username,
12
+ :password => password
13
+ })
14
+
15
+ IFormat::Session.new(attrs)
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,73 @@
1
+ require 'savon'
2
+ require 'iformat/configuration'
3
+ require 'iformat/error'
4
+ require 'iformat/error/bad_session_id'
5
+ require 'iformat/session'
6
+
7
+ module IFormat
8
+
9
+ class Client
10
+ attr_accessor *IFormat::Configuration::VALID_OPTIONS
11
+
12
+ def initialize(options = {})
13
+ IFormat::Configuration::VALID_OPTIONS.each do |key|
14
+ send("#{key}=", options.has_key?(key) ? options[key] : IFormat.config[key])
15
+ end
16
+ end
17
+
18
+ require 'iformat/client/session'
19
+ include IFormat::Client::Session
20
+
21
+ require 'iformat/client/products'
22
+ include IFormat::Client::Products
23
+
24
+ require 'iformat/client/orders'
25
+ include IFormat::Client::Orders
26
+
27
+ protected
28
+
29
+ def request(method, params = {}, options = {})
30
+ response = soap_client.request(method) do
31
+ http.auth.ssl.verify_mode = :none
32
+ soap.body = params unless params.nil? || params.empty?
33
+ end
34
+
35
+ res = response.body["#{method}_response".to_sym]["#{method}_result".to_sym]
36
+ status = res[:status].to_i
37
+ msg = res[:msg]
38
+
39
+ if status < 1
40
+ case status
41
+ when IFormat::Error::BAD_SESSION_ID_STATUS
42
+ raise IFormat::Error::BadSessionId.new(msg, status)
43
+ else
44
+ raise IFormat::Error.new(msg, status)
45
+ end
46
+
47
+ end
48
+
49
+ options[:raw] ? response : res[:result]
50
+ end
51
+
52
+ def session_request(method, params = {}, options = {})
53
+ begin
54
+ request(method, params.merge('sessionID' => current_session.id), options)
55
+ rescue IFormat::Error::BadSessionId
56
+ request(method, params.merge('sessionID' => current_session(:refresh).id), options)
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def current_session(refresh = false)
63
+ @current_session = get_session if @current_session.nil? || refresh
64
+ @current_session
65
+ end
66
+
67
+ def soap_client
68
+ @soap_client ||= Savon::Client.new(wsdl)
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,47 @@
1
+ require 'singleton'
2
+
3
+ module IFormat
4
+
5
+ # Defines constants and methods related to configuration
6
+ class Configuration
7
+ include Singleton
8
+
9
+ # The WSDL URL that will be used to connect if none is set
10
+ DEFAULT_WSDL = 'http://wsdl.iformat.pl/api.xml'
11
+
12
+ # The API usersname if none is set
13
+ DEFAULT_USERNAME = nil
14
+
15
+ # The API password if none is set
16
+ DEFAULT_PASSWORD = nil
17
+
18
+ # An array of valid keys in the options hash when configuring a {IFormat::Client}
19
+ VALID_OPTIONS = [
20
+ :wsdl,
21
+ :username,
22
+ :password
23
+ ]
24
+
25
+ attr_accessor *VALID_OPTIONS
26
+
27
+ def initialize
28
+ reset!
29
+ super
30
+ end
31
+
32
+ def [](key)
33
+ send key
34
+ end
35
+
36
+ private
37
+
38
+ # Reset all configuration options to defaults
39
+ def reset!
40
+ self.wsdl = DEFAULT_WSDL
41
+ self.username = DEFAULT_USERNAME
42
+ self.password = DEFAULT_PASSWORD
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/client_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::AuthorizationError < IFormat::Error::ClientError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/authorization_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::BadSessionId < IFormat::Error::AuthorizationError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/authorization_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::BadUsernameOrPassword < IFormat::Error::AuthorizationError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/authorization_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::BadUsernameOrPasswordOrPasswordsDifferent < IFormat::Error::AuthorizationError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error'
2
+
3
+ module IFormat
4
+
5
+ class Error::ClientError < IFormat::Error
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/client_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::HeaderError < IFormat::Error::ClientError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/client_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::InsertCoin < IFormat::Error::ClientError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/server_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::InternalError < IFormat::Error::ServerError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/client_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::ItemError < IFormat::Error::ClientError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/client_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::LogoError < IFormat::Error::ClientError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/client_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::NotAllLinesHaveLinks < IFormat::Error::ClientError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/client_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::OrderAlreadyExists < IFormat::Error::ClientError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/client_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::OrderClosedNoLinksGenerated < IFormat::Error::ClientError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/client_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::OrderDeletedFromSystem < IFormat::Error::ClientError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/client_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::OrderNotFound < IFormat::Error::ClientError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/client_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::OrderWaitingForLinks < IFormat::Error::ClientError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/client_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::ResultTooBig < IFormat::Error::ClientError
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error'
2
+
3
+ module IFormat
4
+
5
+ class Error::ServerError < IFormat::Error
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'iformat/error/server_error'
2
+
3
+ module IFormat
4
+
5
+ class Error::UnknownError < IFormat::Error::ServerError
6
+ end
7
+
8
+ end
@@ -0,0 +1,31 @@
1
+ module IFormat
2
+
3
+ # Error class for rescuing from all IFormat errors
4
+ class Error < StandardError
5
+ UNKNOWN_ERROR_STATUS = 0
6
+ INTERNAL_ERROR_STATUS = -1
7
+ BAD_SESSION_ID_STATUS = -101
8
+ BAD_USERNAME_OR_PASSWORD_STATUS = -102
9
+ BAD_USERNAME_OR_PASSWORD_OR_PASSWORDS_DIFFERENT_STATUS = -103
10
+ ORDER_ALREADY_EXISTS_STATUS = -1001
11
+ HEADER_ERROR_STATUS = -1002
12
+ ITEM_ERROR_STATUS = -1003
13
+ LOGO_ERROR_STATUS = -1004
14
+ RESULT_TOO_BIG_STATUS = -1005
15
+ INSERT_COIN_STATUS = -1006
16
+ NOT_ALL_LINES_HAVE_LINKS_STATUS = -1012
17
+ ORDER_NOT_FOUND_STATUS = -1013
18
+ ORDER_DELETED_FROM_SYSTEM_STATUS = -1014
19
+ ORDER_CLOSED_NO_LINKS_GENERATED_STATUS = -1015
20
+ ORDER_WAITING_FOR_LINKS_STATUS = -1016
21
+
22
+ attr_reader :status
23
+
24
+ def initialize(message, status = UNKNOWN_ERROR_STATUS)
25
+ @status = status
26
+ super(message)
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,24 @@
1
+ require 'iformat/base'
2
+
3
+ module IFormat
4
+
5
+ class Order < IFormat::Base
6
+ lazy_attr_reader :order_id, :items
7
+
8
+ def id
9
+ @id ||= @attrs[:order_id]
10
+ end
11
+
12
+ def items
13
+ @items ||= []
14
+ end
15
+
16
+ # @param other [IFormat::Order]
17
+ # @return [Boolean]
18
+ def ==(other)
19
+ super || (other.class == self.class && other.id == self.id)
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,20 @@
1
+ require 'iformat/base'
2
+
3
+ module IFormat
4
+
5
+ class OrderItem < IFormat::Base
6
+ lazy_attr_reader :product_id, :issue_id, :type_id
7
+
8
+ def type
9
+ @type ||= @attrs[:type_id]
10
+ end
11
+
12
+ # @param other [IFormat::OrderItem]
13
+ # @return [Boolean]
14
+ def ==(other)
15
+ super || (other.class == self.class && other.product_id == self.product_id && other.issue_id == self.issue_id && other.type_id == self.type_id)
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'iformat/base'
2
+
3
+ module IFormat
4
+
5
+ class Session < IFormat::Base
6
+ lazy_attr_reader :session_id, :timeout
7
+
8
+ def id
9
+ @id ||= @attrs[:session_id]
10
+ end
11
+
12
+ # @param other [IFormat::Session]
13
+ # @return [Boolean]
14
+ def ==(other)
15
+ super || (other.class == self.class && other.id == self.id)
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,3 @@
1
+ module IFormat
2
+ VERSION = '0.0.1'
3
+ end
data/lib/iformat.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'iformat/client'
2
+ require 'iformat/configuration'
3
+ require 'iformat/version'
4
+
5
+ module IFormat
6
+
7
+ # Alias for IFormat::Client.new
8
+ #
9
+ # @return [IFormat::Client]
10
+ def self.new(options = {})
11
+ IFormat::Client.new(options)
12
+ end
13
+
14
+ def self.configure(&block)
15
+ return unless block_given?
16
+
17
+ yield Configuration.instance
18
+ end
19
+
20
+ def self.config
21
+ Configuration.instance
22
+ end
23
+
24
+ # Delegate to IFormat::Client
25
+ def self.method_missing(method, *args, &block)
26
+ return super unless new.respond_to?(method)
27
+
28
+ new.send(method, *args, &block)
29
+ end
30
+
31
+ def self.respond_to?(method, include_private = false)
32
+ new.respond_to?(method, include_private) || super(method, include_private)
33
+ end
34
+
35
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'minitest/autorun'
3
+ require 'turn'
4
+ require 'iformat'
@@ -0,0 +1,55 @@
1
+ require 'helper'
2
+
3
+ describe IFormat::Client do
4
+
5
+ describe 'with module configuration' do
6
+
7
+ before do
8
+ IFormat.configure do |config|
9
+ config.wsdl = 'http://example.com/module.xml'
10
+ config.username = 'Module Username'
11
+ config.password = 'Module Password'
12
+ end
13
+ end
14
+
15
+ after do
16
+ IFormat::Configuration.instance.send(:reset!)
17
+ end
18
+
19
+ it 'inherits module configuration' do
20
+ api = IFormat::Client.new
21
+
22
+ api.wsdl.must_equal 'http://example.com/module.xml'
23
+ api.username.must_equal 'Module Username'
24
+ api.password.must_equal 'Module Password'
25
+ end
26
+
27
+ describe 'with class configuration' do
28
+
29
+ describe 'during initialization' do
30
+ it 'overrides module configuration' do
31
+ api = IFormat::Client.new({:wsdl => 'http://example.com/class.xml', :username => 'Class Username'})
32
+
33
+ api.wsdl.must_equal 'http://example.com/class.xml'
34
+ api.username.must_equal 'Class Username'
35
+ api.password.must_equal 'Module Password'
36
+ end
37
+ end
38
+
39
+ describe 'after initilization' do
40
+ it 'overrides module configuration after initialization' do
41
+ api = IFormat::Client.new
42
+ api.wsdl = 'http://example.com/class.xml'
43
+ api.username = 'Class Username'
44
+
45
+ api.wsdl.must_equal 'http://example.com/class.xml'
46
+ api.username.must_equal 'Class Username'
47
+ api.password.must_equal 'Module Password'
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,53 @@
1
+ require 'helper'
2
+
3
+ describe IFormat do
4
+
5
+ after do
6
+ IFormat::Configuration.instance.send(:reset!)
7
+ end
8
+
9
+ describe '::respond_to?' do
10
+ it 'takes an optional argument' do
11
+ IFormat.respond_to?(:new, true).must_equal true
12
+ end
13
+ end
14
+
15
+ describe '::new' do
16
+ it 'returns an IFormat::Client' do
17
+ IFormat.new.must_be_instance_of IFormat::Client
18
+ end
19
+ end
20
+
21
+ describe '::configure' do
22
+
23
+ describe 'with configuration block' do
24
+
25
+ it 'configures default Client options' do
26
+ IFormat.configure do |config|
27
+ config.wsdl = 'http://example.com/wsdl.xml'
28
+ config.username = 'john'
29
+ config.password = 'doe'
30
+ end
31
+
32
+ IFormat.config.wsdl.must_equal 'http://example.com/wsdl.xml'
33
+ IFormat.config.username.must_equal 'john'
34
+ IFormat.config.password.must_equal 'doe'
35
+ end
36
+
37
+ it 'allows nil option values' do
38
+ IFormat.configure do |config|
39
+ config.wsdl = nil
40
+ config.username = nil
41
+ config.password = nil
42
+ end
43
+
44
+ IFormat.config.wsdl.must_equal nil
45
+ IFormat.config.username.must_equal nil
46
+ IFormat.config.password.must_equal nil
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iformat
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Karol Sarnacki
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-27 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 25
29
+ segments:
30
+ - 0
31
+ - 9
32
+ version: "0.9"
33
+ prerelease: false
34
+ name: savon
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ type: :development
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 15
44
+ segments:
45
+ - 2
46
+ - 0
47
+ - 0
48
+ version: 2.0.0
49
+ prerelease: false
50
+ name: minitest
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ type: :development
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ prerelease: false
64
+ name: rake
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ type: :development
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ prerelease: false
78
+ name: turn
79
+ version_requirements: *id004
80
+ description: A Ruby wrapper for the iFormat API.
81
+ email:
82
+ - sodercober@gmail.com
83
+ executables: []
84
+
85
+ extensions: []
86
+
87
+ extra_rdoc_files: []
88
+
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - iformat.gemspec
97
+ - lib/iformat.rb
98
+ - lib/iformat/base.rb
99
+ - lib/iformat/category.rb
100
+ - lib/iformat/client.rb
101
+ - lib/iformat/client/orders.rb
102
+ - lib/iformat/client/products.rb
103
+ - lib/iformat/client/session.rb
104
+ - lib/iformat/configuration.rb
105
+ - lib/iformat/error.rb
106
+ - lib/iformat/error/authorization_error.rb
107
+ - lib/iformat/error/bad_session_id.rb
108
+ - lib/iformat/error/bad_username_or_password.rb
109
+ - lib/iformat/error/bad_username_or_password_or_passwords_different.rb
110
+ - lib/iformat/error/client_error.rb
111
+ - lib/iformat/error/header_error.rb
112
+ - lib/iformat/error/insert_coin.rb
113
+ - lib/iformat/error/internal_error.rb
114
+ - lib/iformat/error/item_error.rb
115
+ - lib/iformat/error/logo_error.rb
116
+ - lib/iformat/error/not_all_lines_have_links.rb
117
+ - lib/iformat/error/order_already_exists.rb
118
+ - lib/iformat/error/order_closed_no_links_generated.rb
119
+ - lib/iformat/error/order_deleted_from_system.rb
120
+ - lib/iformat/error/order_not_found.rb
121
+ - lib/iformat/error/order_waiting_for_links.rb
122
+ - lib/iformat/error/result_too_big.rb
123
+ - lib/iformat/error/server_error.rb
124
+ - lib/iformat/error/unknown_error.rb
125
+ - lib/iformat/order.rb
126
+ - lib/iformat/order_item.rb
127
+ - lib/iformat/session.rb
128
+ - lib/iformat/version.rb
129
+ - test/helper.rb
130
+ - test/test_client.rb
131
+ - test/test_iformat.rb
132
+ has_rdoc: true
133
+ homepage: https://github.com/sodercober/iformat
134
+ licenses: []
135
+
136
+ post_install_message:
137
+ rdoc_options: []
138
+
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ requirements: []
160
+
161
+ rubyforge_project:
162
+ rubygems_version: 1.6.2
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: iFormat API wrapper
166
+ test_files:
167
+ - test/helper.rb
168
+ - test/test_client.rb
169
+ - test/test_iformat.rb