rivendell-api 0.8 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Rivendell
2
2
  module Api
3
- VERSION = "0.8"
3
+ VERSION = "0.9"
4
4
  end
5
5
  end
@@ -30,7 +30,7 @@ module Rivendell::API
30
30
  options.each { |k,v| send "#{k}=", v }
31
31
  end
32
32
 
33
- attr_accessor :login_name, :password, :host
33
+ attr_accessor :login_name, :password, :host, :encoding
34
34
 
35
35
  def host
36
36
  @host ||= "localhost"
@@ -44,6 +44,17 @@ module Rivendell::API
44
44
  @password ||= ""
45
45
  end
46
46
 
47
+ def encoding
48
+ @encoding ||= "cp1252"
49
+ end
50
+
51
+ def encode(attributes)
52
+ attributes.each_with_object({}) do |(k,v), encoded_atttributes|
53
+ v = v.encode(encoding) if v.respond_to?(:encode)
54
+ encoded_atttributes[k] = v
55
+ end
56
+ end
57
+
47
58
  def rdxport_uri
48
59
  "http://#{host}/rd-bin/rdxport.cgi"
49
60
  end
@@ -88,7 +99,7 @@ module Rivendell::API
88
99
  attributes.delete(:number)
89
100
  attributes[:group_name] ||= attributes.delete(:group)
90
101
 
91
- response = post COMMAND_EDITCART, attributes
102
+ response = post COMMAND_EDITCART, encode(attributes)
92
103
  Rivendell::API::Cart.new(response["cartList"]["cart"])
93
104
  end
94
105
 
@@ -166,7 +177,7 @@ module Rivendell::API
166
177
  attributes[:cart_number] = cart_number
167
178
  attributes[:cut_number] = cut_number
168
179
 
169
- post COMMAND_EDITCUT, attributes
180
+ post COMMAND_EDITCUT, encode(attributes)
170
181
  end
171
182
 
172
183
  def list_cut(cart_number, cut_number)
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe Rivendell::API::Xport do
@@ -66,6 +67,28 @@ describe Rivendell::API::Xport do
66
67
 
67
68
  end
68
69
 
70
+ describe "#encoding" do
71
+
72
+ it "should be 'cp1252' by default" do
73
+ subject.encoding.should == 'cp1252'
74
+ end
75
+
76
+ end
77
+
78
+ describe "#encode" do
79
+
80
+ it "should change string encoding if needed" do
81
+ utf8_attributes = { dummy: "aéèùç".encode("UTF-8") }
82
+ subject.encode(utf8_attributes).should == { dummy: "aéèùç".encode(subject.encoding) }
83
+ end
84
+
85
+ it "should left intact attributes without encoding" do
86
+ attributes = { dummy: 1 }
87
+ subject.encode(attributes).should == { dummy: 1 }
88
+ end
89
+
90
+ end
91
+
69
92
  describe "host" do
70
93
 
71
94
  let(:host) { "example.com" }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rivendell-api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.8'
4
+ version: '0.9'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-19 00:00:00.000000000 Z
12
+ date: 2015-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httmultiparty
@@ -208,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
208
208
  version: '0'
209
209
  segments:
210
210
  - 0
211
- hash: -2208257095706775777
211
+ hash: -4471863522203624397
212
212
  required_rubygems_version: !ruby/object:Gem::Requirement
213
213
  none: false
214
214
  requirements:
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  version: '0'
218
218
  segments:
219
219
  - 0
220
- hash: -2208257095706775777
220
+ hash: -4471863522203624397
221
221
  requirements: []
222
222
  rubyforge_project:
223
223
  rubygems_version: 1.8.23