smspromote 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,10 @@
1
1
  module SmsPromote
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
4
4
 
5
- begin
6
- require 'rest_client'
7
- rescue LoadError
8
- require 'rubygems'
9
- require 'rest_client'
10
- end
5
+ gem 'rest-client', '>= 1.6.0'
6
+
7
+ require 'rest_client'
11
8
 
12
9
  require 'smspromote/message'
13
10
  require 'smspromote/gateway'
@@ -0,0 +1,309 @@
1
+ module Encoding
2
+ GSM_UNICODE = [
3
+ 0x0040, # 0x00 COMMERCIAL AT
4
+ 0x00A3, # 0x01 POUND SIGN
5
+ 0x0024, # 0x02 DOLLAR SIGN
6
+ 0x00A5, # 0x03 YEN SIGN
7
+ 0x00E8, # 0x04 LATIN SMALL LETTER E WITH GRAVE
8
+ 0x00E9, # 0x05 LATIN SMALL LETTER E WITH ACUTE
9
+ 0x00F9, # 0x06 LATIN SMALL LETTER U WITH GRAVE
10
+ 0x00EC, # 0x07 LATIN SMALL LETTER I WITH GRAVE
11
+ 0x00F2, # 0x08 LATIN SMALL LETTER O WITH GRAVE
12
+ 0x00E7, # 0x09 LATIN SMALL LETTER C WITH CEDILLA
13
+ 0x000A, # 0x0A LINE FEED
14
+ 0x00D8, # 0x0B LATIN CAPITAL LETTER O WITH STROKE
15
+ 0x00F8, # 0x0C LATIN SMALL LETTER O WITH STROKE
16
+ 0x000D, # 0x0D CARRIAGE RETURN
17
+ 0x00C5, # 0x0E LATIN CAPITAL LETTER A WITH RING ABOVE
18
+ 0x00E5, # 0x0F LATIN SMALL LETTER A WITH RING ABOVE
19
+ 0x0394, # 0x10 GREEK CAPITAL LETTER DELTA
20
+ 0x005F, # 0x11 LOW LINE
21
+ 0x03A6, # 0x12 GREEK CAPITAL LETTER PHI
22
+ 0x0393, # 0x13 GREEK CAPITAL LETTER GAMMA
23
+ 0x039B, # 0x14 GREEK CAPITAL LETTER LAMDA
24
+ 0x03A9, # 0x15 GREEK CAPITAL LETTER OMEGA
25
+ 0x03A0, # 0x16 GREEK CAPITAL LETTER PI
26
+ 0x03A8, # 0x17 GREEK CAPITAL LETTER PSI
27
+ 0x03A3, # 0x18 GREEK CAPITAL LETTER SIGMA
28
+ 0x0398, # 0x19 GREEK CAPITAL LETTER THETA
29
+ 0x039E, # 0x1A GREEK CAPITAL LETTER XI
30
+ 0x00A0, # 0x1B ESCAPE TO EXTENSION TABLE
31
+ 0x00C6, # 0x1C LATIN CAPITAL LETTER AE
32
+ 0x00E6, # 0x1D LATIN SMALL LETTER AE
33
+ 0x00DF, # 0x1E LATIN SMALL LETTER SHARP S (German)
34
+ 0x00C9, # 0x1F LATIN CAPITAL LETTER E WITH ACUTE
35
+ 0x0020, # 0x20 SPACE
36
+ 0x0021, # 0x21 EXCLAMATION MARK
37
+ 0x0022, # 0x22 QUOTATION MARK
38
+ 0x0023, # 0x23 NUMBER SIGN
39
+ 0x00A4, # 0x24 CURRENCY SIGN
40
+ 0x0025, # 0x25 PERCENT SIGN
41
+ 0x0026, # 0x26 AMPERSAND
42
+ 0x0027, # 0x27 APOSTROPHE
43
+ 0x0028, # 0x28 LEFT PARENTHESIS
44
+ 0x0029, # 0x29 RIGHT PARENTHESIS
45
+ 0x002A, # 0x2A ASTERISK
46
+ 0x002B, # 0x2B PLUS SIGN
47
+ 0x002C, # 0x2C COMMA
48
+ 0x002D, # 0x2D HYPHEN-MINUS
49
+ 0x002E, # 0x2E FULL STOP
50
+ 0x002F, # 0x2F SOLIDUS
51
+ 0x0030, # 0x30 DIGIT ZERO
52
+ 0x0031, # 0x31 DIGIT ONE
53
+ 0x0032, # 0x32 DIGIT TWO
54
+ 0x0033, # 0x33 DIGIT THREE
55
+ 0x0034, # 0x34 DIGIT FOUR
56
+ 0x0035, # 0x35 DIGIT FIVE
57
+ 0x0036, # 0x36 DIGIT SIX
58
+ 0x0037, # 0x37 DIGIT SEVEN
59
+ 0x0038, # 0x38 DIGIT EIGHT
60
+ 0x0039, # 0x39 DIGIT NINE
61
+ 0x003A, # 0x3A COLON
62
+ 0x003B, # 0x3B SEMICOLON
63
+ 0x003C, # 0x3C LESS-THAN SIGN
64
+ 0x003D, # 0x3D EQUALS SIGN
65
+ 0x003E, # 0x3E GREATER-THAN SIGN
66
+ 0x003F, # 0x3F QUESTION MARK
67
+ 0x00A1, # 0x40 INVERTED EXCLAMATION MARK
68
+ 0x0041, # 0x41 LATIN CAPITAL LETTER A
69
+ 0x0042, # 0x42 LATIN CAPITAL LETTER B
70
+ 0x0043, # 0x43 LATIN CAPITAL LETTER C
71
+ 0x0044, # 0x44 LATIN CAPITAL LETTER D
72
+ 0x0045, # 0x45 LATIN CAPITAL LETTER E
73
+ 0x0046, # 0x46 LATIN CAPITAL LETTER F
74
+ 0x0047, # 0x47 LATIN CAPITAL LETTER G
75
+ 0x0048, # 0x48 LATIN CAPITAL LETTER H
76
+ 0x0049, # 0x49 LATIN CAPITAL LETTER I
77
+ 0x004A, # 0x4A LATIN CAPITAL LETTER J
78
+ 0x004B, # 0x4B LATIN CAPITAL LETTER K
79
+ 0x004C, # 0x4C LATIN CAPITAL LETTER L
80
+ 0x004D, # 0x4D LATIN CAPITAL LETTER M
81
+ 0x004E, # 0x4E LATIN CAPITAL LETTER N
82
+ 0x004F, # 0x4F LATIN CAPITAL LETTER O
83
+ 0x0050, # 0x50 LATIN CAPITAL LETTER P
84
+ 0x0051, # 0x51 LATIN CAPITAL LETTER Q
85
+ 0x0052, # 0x52 LATIN CAPITAL LETTER R
86
+ 0x0053, # 0x53 LATIN CAPITAL LETTER S
87
+ 0x0054, # 0x54 LATIN CAPITAL LETTER T
88
+ 0x0055, # 0x55 LATIN CAPITAL LETTER U
89
+ 0x0056, # 0x56 LATIN CAPITAL LETTER V
90
+ 0x0057, # 0x57 LATIN CAPITAL LETTER W
91
+ 0x0058, # 0x58 LATIN CAPITAL LETTER X
92
+ 0x0059, # 0x59 LATIN CAPITAL LETTER Y
93
+ 0x005A, # 0x5A LATIN CAPITAL LETTER Z
94
+ 0x00C4, # 0x5B LATIN CAPITAL LETTER A WITH DIAERESIS
95
+ 0x00D6, # 0x5C LATIN CAPITAL LETTER O WITH DIAERESIS
96
+ 0x00D1, # 0x5D LATIN CAPITAL LETTER N WITH TILDE
97
+ 0x00DC, # 0x5E LATIN CAPITAL LETTER U WITH DIAERESIS
98
+ 0x00A7, # 0x5F SECTION SIGN
99
+ 0x00BF, # 0x60 INVERTED QUESTION MARK
100
+ 0x0061, # 0x61 LATIN SMALL LETTER A
101
+ 0x0062, # 0x62 LATIN SMALL LETTER B
102
+ 0x0063, # 0x63 LATIN SMALL LETTER C
103
+ 0x0064, # 0x64 LATIN SMALL LETTER D
104
+ 0x0065, # 0x65 LATIN SMALL LETTER E
105
+ 0x0066, # 0x66 LATIN SMALL LETTER F
106
+ 0x0067, # 0x67 LATIN SMALL LETTER G
107
+ 0x0068, # 0x68 LATIN SMALL LETTER H
108
+ 0x0069, # 0x69 LATIN SMALL LETTER I
109
+ 0x006A, # 0x6A LATIN SMALL LETTER J
110
+ 0x006B, # 0x6B LATIN SMALL LETTER K
111
+ 0x006C, # 0x6C LATIN SMALL LETTER L
112
+ 0x006D, # 0x6D LATIN SMALL LETTER M
113
+ 0x006E, # 0x6E LATIN SMALL LETTER N
114
+ 0x006F, # 0x6F LATIN SMALL LETTER O
115
+ 0x0070, # 0x70 LATIN SMALL LETTER P
116
+ 0x0071, # 0x71 LATIN SMALL LETTER Q
117
+ 0x0072, # 0x72 LATIN SMALL LETTER R
118
+ 0x0073, # 0x73 LATIN SMALL LETTER S
119
+ 0x0074, # 0x74 LATIN SMALL LETTER T
120
+ 0x0075, # 0x75 LATIN SMALL LETTER U
121
+ 0x0076, # 0x76 LATIN SMALL LETTER V
122
+ 0x0077, # 0x77 LATIN SMALL LETTER W
123
+ 0x0078, # 0x78 LATIN SMALL LETTER X
124
+ 0x0079, # 0x79 LATIN SMALL LETTER Y
125
+ 0x007A, # 0x7A LATIN SMALL LETTER Z
126
+ 0x00E4, # 0x7B LATIN SMALL LETTER A WITH DIAERESIS
127
+ 0x00F6, # 0x7C LATIN SMALL LETTER O WITH DIAERESIS
128
+ 0x00F1, # 0x7D LATIN SMALL LETTER N WITH TILDE
129
+ 0x00FC, # 0x7E LATIN SMALL LETTER U WITH DIAERESIS
130
+ 0x00E0 # 0x7F LATIN SMALL LETTER A WITH GRAVE
131
+ ]
132
+
133
+ GSM_ESCAPES = [
134
+ { :from => 0x0A, :to => 0x000C }, /* FORM FEED
135
+ { :from => 0x14, :to => 0x005E }, /* CIRCUMFLEX ACCENT
136
+ { :from => 0x28, :to => 0x007B }, /* LEFT CURLY BRACKET
137
+ { :from => 0x29, :to => 0x007D }, /* RIGHT CURLY BRACKET
138
+ { :from => 0x2F, :to => 0x005C }, /* REVERSE SOLIDUS
139
+ { :from => 0x3C, :to => 0x005B }, /* LEFT SQUARE BRACKET
140
+ { :from => 0x3D, :to => 0x007E }, /* TILDE
141
+ { :from => 0x3E, :to => 0x005D }, /* RIGHT SQUARE BRACKET
142
+ { :from => 0x40, :to => 0x007C }, /* VERTICAL LINE
143
+ { :from => 0x65, :to => 0x20AC }, /* EURO SIGN
144
+ { :from => 0 , :to => 0 }
145
+ ]
146
+
147
+ end
148
+
149
+
150
+ static int
151
+ gsm7_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
152
+ {
153
+ int i = 0;
154
+ if( *s > 0x7f )
155
+ return RET_ILSEQ;
156
+ else if( *s == 0x1B ) {
157
+ if( n >= 2 ) {
158
+ while( gsmEscapes[ i ].from ) {
159
+ if( gsmEscapes[ i ].from == s[1] ) {
160
+ *pwc = gsmEscapes[ i ].to;
161
+ return 2;
162
+ }
163
+ i++;
164
+ }
165
+ return RET_ILSEQ;
166
+ } else
167
+ return RET_TOOFEW( 1 );
168
+ }
169
+ *pwc = gsmToUnicode[ *s ];
170
+ return 1;
171
+ }
172
+ static int
173
+ gsm7_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
174
+ {
175
+ unsigned char s1, s2;
176
+ s1 = (wc & 0xff00) >> 8;
177
+ s2 = wc & 0x00ff;
178
+ if( s1 == 0x00 ) {
179
+ if( s2 == 0xA || s2 == 0xD ||
180
+ (s2 >= 0x20 && s2 <= 0x23 ) || (s2 >= 0x25 && s2 <= 0x3f)
181
+ || (s2 >= 0x41 && s2 <= 0x5A) || (s2 >= 0x61 && s2 <= 0x7A) ) {
182
+ *r = s2;
183
+ return 1;
184
+ } else {
185
+ switch( s2 ) {
186
+ case 0x24: *r = 0x02; return 1;
187
+ case 0x40: *r = 0x00; return 1;
188
+ case 0x5b: if( n >= 2 ) {r[0] = 0x1b; r[1] = 0x3c; return 2; }
189
+ else return RET_TOOSMALL;
190
+ case 0x5c: if( n >= 2 ) {r[0] = 0x1b; r[1] = 0x2f; return 2; }
191
+ else return RET_TOOSMALL;
192
+ case 0x5d: if( n >= 2 ) {r[0] = 0x1b; r[1] = 0x3e; return 2; }
193
+ else return RET_TOOSMALL;
194
+ case 0x5e: if( n >= 2 ) {r[0] = 0x1b; r[1] = 0x14; return 2; }
195
+ else return RET_TOOSMALL;
196
+ case 0x5f: *r = 0x11; return 1;
197
+ case 0x7b: if( n >= 2 ) {r[0] = 0x1b; r[1] = 0x28; return 2; }
198
+ else return RET_TOOSMALL;
199
+ case 0x7c: if( n >= 2 ) {r[0] = 0x1b; r[1] = 0x40; return 2; }
200
+ else return RET_TOOSMALL;
201
+ case 0x7d: if( n >= 2 ) {r[0] = 0x1b; r[1] = 0x29; return 2; }
202
+ else return RET_TOOSMALL;
203
+ case 0x7e: if( n >= 2 ) {r[0] = 0x1b; r[1] = 0x3d; return 2; }
204
+ else return RET_TOOSMALL;
205
+ case 0xa3: *r = 0x01; return 1;
206
+ case 0xa4: *r = 0x24; return 1;
207
+ case 0xa5: *r = 0x03; return 1;
208
+ case 0xa7: *r = 0x5f; return 1;
209
+ case 0xb0: *r = 0x24; return 1;
210
+ case 0xbf: *r = 0x60; return 1;
211
+ case 0xc5: *r = 0x0e; return 1;
212
+ case 0xc6: *r = 0x1c; return 1;
213
+ case 0xc7: *r = 0x09; return 1;
214
+ case 0xc9: *r = 0x1f; return 1;
215
+ case 0xc4: *r = 0x5b; return 1;
216
+ case 0xd1: *r = 0x5d; return 1;
217
+ case 0xd6: *r = 0x5c; return 1;
218
+ case 0xd8: *r = 0x0b; return 1;
219
+ case 0xdc: *r = 0x5e; return 1;
220
+ case 0xdf: *r = 0x1e; return 1;
221
+ case 0xe0: *r = 0x7f; return 1;
222
+ case 0xe4: *r = 0x7b; return 1;
223
+ case 0xe5: *r = 0x0f; return 1;
224
+ case 0xe6: *r = 0x1d; return 1;
225
+ case 0xe7: *r = 0x09; return 1;
226
+ case 0xe8: *r = 0x04; return 1;
227
+ case 0xe9: *r = 0x05; return 1;
228
+ case 0xec: *r = 0x07; return 1;
229
+ case 0xf1: *r = 0x7d; return 1;
230
+ case 0xf2: *r = 0x08; return 1;
231
+ case 0xf6: *r = 0x7c; return 1;
232
+ case 0xf8: *r = 0x0c; return 1;
233
+ case 0xf9: *r = 0x06; return 1;
234
+ case 0xfc: *r = 0x7e; return 1;
235
+ /* one way mappings
236
+ case 0xc0: *r = 0x41; return 1;
237
+ case 0xc1: *r = 0x41; return 1;
238
+ case 0xc2: *r = 0x41; return 1;
239
+ case 0xc3: *r = 0x41; return 1;
240
+ case 0xc8: *r = 0x45; return 1;
241
+ case 0xca: *r = 0x45; return 1;
242
+ case 0xcb: *r = 0x45; return 1;
243
+ case 0xcc: *r = 0x49; return 1;
244
+ case 0xcd: *r = 0x49; return 1;
245
+ case 0xce: *r = 0x49; return 1;
246
+ case 0xcf: *r = 0x49; return 1;
247
+ case 0xd2: *r = 0x4f; return 1;
248
+ case 0xd3: *r = 0x4f; return 1;
249
+ case 0xd4: *r = 0x4f; return 1;
250
+ case 0xd5: *r = 0x4f; return 1;
251
+ case 0xd9: *r = 0x55; return 1;
252
+ case 0xda: *r = 0x55; return 1;
253
+ case 0xdb: *r = 0x55; return 1;
254
+ case 0xdd: *r = 0x59; return 1;
255
+ case 0xe1: *r = 0x61; return 1;
256
+ case 0xe2: *r = 0x61; return 1;
257
+ case 0xe3: *r = 0x61; return 1;
258
+ case 0xea: *r = 0x65; return 1;
259
+ case 0xeb: *r = 0x65; return 1;
260
+ case 0xed: *r = 0x69; return 1;
261
+ case 0xee: *r = 0x69; return 1;
262
+ case 0xef: *r = 0x69; return 1;
263
+ case 0xf3: *r = 0x6f; return 1;
264
+ case 0xf4: *r = 0x6f; return 1;
265
+ case 0xf5: *r = 0x6f; return 1;
266
+ case 0xfa: *r = 0x75; return 1;
267
+ case 0xfb: *r = 0x75; return 1;
268
+ case 0xfd: *r = 0x79; return 1;
269
+ case 0xff: *r = 0x79; return 1;
270
+ }
271
+ }
272
+ return RET_ILUNI;
273
+ } else if( s1 == 0x20 ) {
274
+ if( s2 == 0xac ) {
275
+ if( n >= 2 ) {
276
+ r[0] = 0x1b; r[1] = 0x65; return 2;
277
+ } else return RET_TOOSMALL;
278
+ }
279
+ } else if( s1 = 0x03 ) {
280
+ switch( s2 ) {
281
+ case 0x94: *r = 0x10; return 1;
282
+ case 0xa6: *r = 0x12; return 1;
283
+ case 0x93: *r = 0x13; return 1;
284
+ case 0x9b: *r = 0x14; return 1;
285
+ case 0xa9: *r = 0x15; return 1;
286
+ case 0xa0: *r = 0x16; return 1;
287
+ case 0xa8: *r = 0x17; return 1;
288
+ case 0xa3: *r = 0x18; return 1;
289
+ case 0x98: *r = 0x19; return 1;
290
+ case 0x9e: *r = 0x1a; return 1;
291
+ case 0x91: *r = 0x41; return 1;
292
+ case 0x92: *r = 0x42; return 1;
293
+ case 0x95: *r = 0x45; return 1;
294
+ case 0x97: *r = 0x48; return 1;
295
+ case 0x99: *r = 0x49; return 1;
296
+ case 0x9a: *r = 0x4b; return 1;
297
+ case 0x9c: *r = 0x4d; return 1;
298
+ case 0x9d: *r = 0x4e; return 1;
299
+ case 0x9f: *r = 0x4f; return 1;
300
+ case 0xa1: *r = 0x50; return 1;
301
+ case 0xa4: *r = 0x54; return 1;
302
+ case 0xa5: *r = 0x55; return 1;
303
+ case 0xa7: *r = 0x58; return 1;
304
+ case 0x96: *r = 0x5a; return 1;
305
+ }
306
+ return RET_ILUNI;
307
+ }
308
+ return RET_ILUNI;
309
+ }
@@ -47,6 +47,12 @@ module SmsPromote
47
47
  message
48
48
  end
49
49
 
50
+ # returns the credits left for the gateway
51
+ def credits
52
+ url = @options[:secure] ? "https://" : "http://"
53
+ RestClient.get("gateway.smspromote.de/credits/?key=#{@api_key}").to_f
54
+ end
55
+
50
56
  # returns the response message hash based on the body data
51
57
  def parse_response(body)
52
58
  lines = body.split(/\n/)
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smspromote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
5
11
  platform: ruby
6
12
  authors:
7
13
  - Vincent Landgraf
@@ -9,39 +15,53 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-07-11 00:00:00 +02:00
18
+ date: 2010-07-24 00:00:00 +02:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: rest-client
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 1
32
+ - 6
33
+ - 0
23
34
  version: 1.6.0
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  - !ruby/object:Gem::Dependency
26
38
  name: rake
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
43
  - - ">="
32
44
  - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
33
48
  version: "0"
34
- version:
49
+ type: :development
50
+ version_requirements: *id002
35
51
  - !ruby/object:Gem::Dependency
36
52
  name: rspec
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
40
56
  requirements:
41
57
  - - ">="
42
58
  - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
43
62
  version: "0"
44
- version:
63
+ type: :development
64
+ version_requirements: *id003
45
65
  description: ""
46
66
  email:
47
67
  - vilandgr@googlemail.com
@@ -52,6 +72,7 @@ extensions: []
52
72
  extra_rdoc_files: []
53
73
 
54
74
  files:
75
+ - lib/smspromote/encoding.rb
55
76
  - lib/smspromote/gateway.rb
56
77
  - lib/smspromote/message.rb
57
78
  - lib/smspromote.rb
@@ -67,21 +88,29 @@ rdoc_options: []
67
88
  require_paths:
68
89
  - lib
69
90
  required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
70
92
  requirements:
71
93
  - - ">="
72
94
  - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
73
98
  version: "0"
74
- version:
75
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
76
101
  requirements:
77
102
  - - ">="
78
103
  - !ruby/object:Gem::Version
104
+ hash: 17
105
+ segments:
106
+ - 1
107
+ - 3
108
+ - 5
79
109
  version: 1.3.5
80
- version:
81
110
  requirements: []
82
111
 
83
112
  rubyforge_project:
84
- rubygems_version: 1.3.5
113
+ rubygems_version: 1.3.7
85
114
  signing_key:
86
115
  specification_version: 3
87
116
  summary: this gem helps sending sms using the smspromote.de sms gateway