mymemory 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -13,3 +13,4 @@ pkg
13
13
  rdoc
14
14
  spec/reports
15
15
  tmp
16
+ .DS_Store
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Mymemory
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/spaghetticode/mymemory.png)](http://travis-ci.org/spaghetticode/mymemory)
4
+
3
5
  A (very) basic wrapper on mymemory.com translation resful API. See the
4
6
  [mymemory website](http://mymemory.translated.net/doc/spec.php) for usage
5
7
  constraints.
@@ -29,7 +31,19 @@ Or install it yourself as:
29
31
  Mymemory.translate(text, :from => :en, :to => :it)
30
32
  # => 'una rosa per Emily'
31
33
  ```
32
- The ```from => :en``` key is optional as long as the original language is english.
34
+ The ```:from => :en``` pair is optional as long as the original language is english.
35
+
36
+
37
+ ## Configuration
38
+
39
+ It's totally optional, but providing an email currently gives you extra free translations.
40
+ To set the email parameter:
41
+ ```ruby
42
+ Mymemory.config.email = 'info@example.com'
43
+ ```
44
+ This will add `&de=info@example.com` to the query url.
45
+
46
+
33
47
 
34
48
  ## Contributing
35
49
 
@@ -1,8 +1,13 @@
1
1
  require 'open-uri'
2
2
  require 'mymemory/version'
3
3
  require 'mymemory/translation'
4
+ require 'active_support/configurable'
4
5
 
5
6
  module Mymemory
7
+ include ActiveSupport::Configurable
8
+
9
+ config_accessor :email
10
+
6
11
  class LanguageMissingError < Exception
7
12
  def message
8
13
  'please provide a target language value'
@@ -14,13 +14,17 @@ module Mymemory
14
14
  end
15
15
 
16
16
  def url
17
- URI.escape("#{BASE_URL}?q=#{text}&langpair=#{lang_pair}")
17
+ URI.escape("#{BASE_URL}?q=#{text}&langpair=#{lang_pair}#{email_key}")
18
18
  end
19
19
 
20
20
  def lang_pair
21
21
  [from, to].join('|')
22
22
  end
23
23
 
24
+ def email_key
25
+ config_email && "&de=#{config_email}"
26
+ end
27
+
24
28
  def translated_text
25
29
  parsed_response['responseData']['translatedText']
26
30
  end
@@ -34,5 +38,9 @@ module Mymemory
34
38
  def response
35
39
  @response ||= HTTParty.get(url)
36
40
  end
41
+
42
+ def config_email
43
+ Mymemory.config.email
44
+ end
37
45
  end
38
46
  end
@@ -1,3 +1,3 @@
1
1
  module Mymemory
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.0'
3
3
  end
@@ -16,9 +16,13 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Mymemory::VERSION
17
17
 
18
18
  gem.add_dependency 'rake'
19
+ gem.add_dependency 'json'
19
20
  gem.add_dependency 'httparty'
20
- gem.add_development_dependency 'rspec'
21
- gem.add_development_dependency 'guard-rspec'
21
+ gem.add_dependency 'activesupport'
22
22
  gem.add_development_dependency 'vcr'
23
+ gem.add_development_dependency 'rspec'
23
24
  gem.add_development_dependency 'fakeweb'
25
+ gem.add_development_dependency 'guard-rspec'
26
+ gem.add_development_dependency 'rb-readline'
27
+ gem.add_development_dependency 'rb-fsevent', '~> 0.9.1'
24
28
  end
@@ -19,6 +19,17 @@ module Mymemory
19
19
  url = 'http://mymemory.translated.net/api/get?q=hello%20world&langpair=en%7Cit'
20
20
  subject.url.should == url
21
21
  end
22
+
23
+ context 'when email address is present in configuration' do
24
+ let(:email) { 'info@example.com' }
25
+
26
+ before { Mymemory.config.email = email }
27
+ after { Mymemory.config.email = nil }
28
+
29
+ it 'appends the email param to the url' do
30
+ subject.url.should =~ /de=#{email}$/
31
+ end
32
+ end
22
33
  end
23
34
 
24
35
  context 'when the target language is missing' do
metadata CHANGED
@@ -1,119 +1,174 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mymemory
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - andrea longhi
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-11-22 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-02-22 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: rake
16
- requirement: !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
17
23
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
22
31
  type: :runtime
32
+ requirement: *id001
23
33
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
34
+ - !ruby/object:Gem::Dependency
35
+ name: json
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
25
37
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ type: :runtime
46
+ requirement: *id002
47
+ prerelease: false
48
+ - !ruby/object:Gem::Dependency
31
49
  name: httparty
32
- requirement: !ruby/object:Gem::Requirement
50
+ version_requirements: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ type: :runtime
60
+ requirement: *id003
61
+ prerelease: false
62
+ - !ruby/object:Gem::Dependency
63
+ name: activesupport
64
+ version_requirements: &id004 !ruby/object:Gem::Requirement
33
65
  none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
38
73
  type: :runtime
74
+ requirement: *id004
39
75
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
76
+ - !ruby/object:Gem::Dependency
77
+ name: vcr
78
+ version_requirements: &id005 !ruby/object:Gem::Requirement
41
79
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ type: :development
88
+ requirement: *id005
89
+ prerelease: false
90
+ - !ruby/object:Gem::Dependency
47
91
  name: rspec
48
- requirement: !ruby/object:Gem::Requirement
92
+ version_requirements: &id006 !ruby/object:Gem::Requirement
49
93
  none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
54
101
  type: :development
102
+ requirement: *id006
55
103
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
104
+ - !ruby/object:Gem::Dependency
105
+ name: fakeweb
106
+ version_requirements: &id007 !ruby/object:Gem::Requirement
57
107
  none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ type: :development
116
+ requirement: *id007
117
+ prerelease: false
118
+ - !ruby/object:Gem::Dependency
63
119
  name: guard-rspec
64
- requirement: !ruby/object:Gem::Requirement
120
+ version_requirements: &id008 !ruby/object:Gem::Requirement
65
121
  none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
70
129
  type: :development
130
+ requirement: *id008
71
131
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: vcr
80
- requirement: !ruby/object:Gem::Requirement
132
+ - !ruby/object:Gem::Dependency
133
+ name: rb-readline
134
+ version_requirements: &id009 !ruby/object:Gem::Requirement
81
135
  none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ hash: 3
140
+ segments:
141
+ - 0
142
+ version: "0"
86
143
  type: :development
144
+ requirement: *id009
87
145
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: fakeweb
96
- requirement: !ruby/object:Gem::Requirement
146
+ - !ruby/object:Gem::Dependency
147
+ name: rb-fsevent
148
+ version_requirements: &id010 !ruby/object:Gem::Requirement
97
149
  none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
150
+ requirements:
151
+ - - ~>
152
+ - !ruby/object:Gem::Version
153
+ hash: 57
154
+ segments:
155
+ - 0
156
+ - 9
157
+ - 1
158
+ version: 0.9.1
102
159
  type: :development
160
+ requirement: *id010
103
161
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
162
  description: A (very) basic wrapper on mymemory.com translation resful API
111
- email:
163
+ email:
112
164
  - andrea@spaghetticode.it
113
165
  executables: []
166
+
114
167
  extensions: []
168
+
115
169
  extra_rdoc_files: []
116
- files:
170
+
171
+ files:
117
172
  - .gitignore
118
173
  - .travis.yml
119
174
  - Gemfile
@@ -133,35 +188,38 @@ files:
133
188
  - spec/vcr_config.rb
134
189
  homepage: https://github.com/spaghetticode/mymemory
135
190
  licenses: []
191
+
136
192
  post_install_message:
137
193
  rdoc_options: []
138
- require_paths:
194
+
195
+ require_paths:
139
196
  - lib
140
- required_ruby_version: !ruby/object:Gem::Requirement
197
+ required_ruby_version: !ruby/object:Gem::Requirement
141
198
  none: false
142
- requirements:
143
- - - ! '>='
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- segments:
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ hash: 3
203
+ segments:
147
204
  - 0
148
- hash: -1638617341322682128
149
- required_rubygems_version: !ruby/object:Gem::Requirement
205
+ version: "0"
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
207
  none: false
151
- requirements:
152
- - - ! '>='
153
- - !ruby/object:Gem::Version
154
- version: '0'
155
- segments:
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ hash: 3
212
+ segments:
156
213
  - 0
157
- hash: -1638617341322682128
214
+ version: "0"
158
215
  requirements: []
216
+
159
217
  rubyforge_project:
160
218
  rubygems_version: 1.8.24
161
219
  signing_key:
162
220
  specification_version: 3
163
221
  summary: A (very) basic wrapper on mymemory.com translation resful API
164
- test_files:
222
+ test_files:
165
223
  - spec/cassettes/Mymemory/when_making_external_API_calls/returns_expected_translation.yml
166
224
  - spec/fixtures/hello_world.json
167
225
  - spec/mymemory/translation_spec.rb