neweden 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,8 +3,6 @@ source "http://rubygems.org"
3
3
  gem "typhoeus"
4
4
  gem "nokogiri"
5
5
  gem "json"
6
- gem "awesome_print"
7
- gem "active_support"
8
6
 
9
7
  # Add dependencies to develop your gem here.
10
8
  # Include everything needed to run rake, tests, features, etc.
@@ -12,4 +10,5 @@ group :development do
12
10
  gem "shoulda-context"
13
11
  gem "bundler"
14
12
  gem "jeweler"
13
+ gem "awesome_print"
15
14
  end
data/Gemfile.lock CHANGED
@@ -1,19 +1,19 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- active_support (3.0.0)
5
- activesupport (= 3.0.0)
6
- activesupport (3.0.0)
7
4
  awesome_print (1.0.2)
8
5
  git (1.2.5)
9
6
  jeweler (1.8.3)
10
7
  bundler (~> 1.0)
11
8
  git (>= 1.2.5)
12
9
  rake
10
+ rdoc
13
11
  json (1.6.6)
14
12
  mime-types (1.18)
15
13
  nokogiri (1.5.2)
16
14
  rake (0.9.2.2)
15
+ rdoc (3.12)
16
+ json (~> 1.4)
17
17
  shoulda-context (1.0.0)
18
18
  typhoeus (0.3.3)
19
19
  mime-types
@@ -22,7 +22,6 @@ PLATFORMS
22
22
  ruby
23
23
 
24
24
  DEPENDENCIES
25
- active_support
26
25
  awesome_print
27
26
  bundler
28
27
  jeweler
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.0
data/init.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'typhoeus'
2
2
  require 'nokogiri'
3
3
  require 'awesome_print'
4
- require 'active_support/core_ext/hash/conversions'
5
4
 
5
+ require File.join(File.dirname(__FILE__), 'lib', 'string_extensions')
6
+ require File.join(File.dirname(__FILE__), 'lib', 'hash_extensions')
6
7
  require File.join(File.dirname(__FILE__), 'lib', 'neweden', 'errors')
7
8
  require File.join(File.dirname(__FILE__), 'lib', 'neweden', 'account')
8
9
  require File.join(File.dirname(__FILE__), 'lib', 'neweden', 'api')
@@ -0,0 +1,62 @@
1
+ # USAGE: Hash.from_xml:(YOUR_XML_STRING)
2
+ # modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
3
+ # Thanks to Dmitry Mozzherin (https://gist.github.com/335286)
4
+ class Hash
5
+ class << self
6
+ def from_xml(xml_io)
7
+ begin
8
+ result = Nokogiri::XML(xml_io)
9
+ return { result.root.name.to_sym => xml_node_to_hash(result.root)}
10
+ rescue Exception => e
11
+ # raise your custom exception here
12
+ end
13
+ end
14
+
15
+ def xml_node_to_hash(node)
16
+ # If we are at the root of the document, start the hash
17
+ if node.element?
18
+ result_hash = {}
19
+ if node.attributes != {}
20
+ result_hash[:attributes] = {}
21
+ node.attributes.keys.each do |key|
22
+ result_hash[:attributes][node.attributes[key].name.to_sym] = prepare(node.attributes[key].value)
23
+ end
24
+ end
25
+ if node.children.size > 0
26
+ node.children.each do |child|
27
+ result = xml_node_to_hash(child)
28
+
29
+ if child.name == "text"
30
+ unless child.next_sibling || child.previous_sibling
31
+ return prepare(result)
32
+ end
33
+ elsif result_hash[child.name.to_sym]
34
+ if result_hash[child.name.to_sym].is_a?(Object::Array)
35
+ result_hash[child.name.to_sym] << prepare(result)
36
+ else
37
+ result_hash[child.name.to_sym] = [result_hash[child.name.to_sym]] << prepare(result)
38
+ end
39
+ else
40
+ result_hash[child.name.to_sym] = prepare(result)
41
+ end
42
+ end
43
+
44
+ return result_hash
45
+ else
46
+ return result_hash
47
+ end
48
+ else
49
+ return prepare(node.content.to_s)
50
+ end
51
+ end
52
+
53
+ def prepare(data)
54
+ (data.class == String && data.to_i.to_s == data) ? data.to_i : data
55
+ end
56
+ end
57
+
58
+ def to_struct(struct_name)
59
+ Struct.new(struct_name,*keys).new(*values)
60
+ end
61
+ end
62
+
data/lib/neweden.rb CHANGED
@@ -26,7 +26,7 @@ class NewEden
26
26
  def request(endpoint, method = :post, params = {})
27
27
  xml = handle_response(raw_request(endpoint, method, params))
28
28
  if xml
29
- symbolize_keys(Hash.from_xml((xml/:eveapi/:result).to_s))[:result] rescue raise XMLParsingError, "No result in set"
29
+ Hash.from_xml((xml/:eveapi/:result).to_s)[:result] # rescue raise XMLParsingError, "No result in set"
30
30
  else
31
31
  raise XMLParsingError, "No XML parsed successfully"
32
32
  end
@@ -109,26 +109,25 @@ class NewEden
109
109
  endpoint.strip.gsub(/^\/+/, '')
110
110
  end
111
111
 
112
- def symbolize_keys(myhash)
113
- myhash.symbolize_keys!
114
- myhash.keys.each do |key|
115
- if myhash[key].kind_of?(Hash)
116
- symbolize_keys(myhash[key])
117
- elsif myhash[key].kind_of?(Array)
118
- myhash[key].each do |element|
119
- symbolize_keys(element) if element.kind_of?(Hash)
120
- end
121
- elsif myhash[key].is_a?(String)
122
- if myhash[key].strip =~ /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/
123
- myhash[key] = DateTime.parse(myhash[key]).to_time
124
- elsif myhash[key].strip =~ /^\d+$/
125
- myhash[key] = myhash[key].to_i
126
- elsif myhash[key].strip =~ /^\d+\.\d+$/
127
- myhash[key] = myhash[key].to_f
128
- end
129
- end
130
- end
131
-
132
- myhash
133
- end
112
+ # def symbolize_keys(myhash)
113
+ # myhash.keys.each do |key|
114
+ # if myhash[key].kind_of?(Hash)
115
+ # symbolize_keys(myhash[key])
116
+ # elsif myhash[key].kind_of?(Array)
117
+ # myhash[key].each do |element|
118
+ # symbolize_keys(element) if element.kind_of?(Hash)
119
+ # end
120
+ # elsif myhash[key].is_a?(String)
121
+ # if myhash[key].strip =~ /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/
122
+ # myhash[key] = DateTime.parse(myhash[key]).to_time
123
+ # elsif myhash[key].strip =~ /^\d+$/
124
+ # myhash[key] = myhash[key].to_i
125
+ # elsif myhash[key].strip =~ /^\d+\.\d+$/
126
+ # myhash[key] = myhash[key].to_f
127
+ # end
128
+ # end
129
+ # end
130
+
131
+ # myhash
132
+ # end
134
133
  end
@@ -0,0 +1,11 @@
1
+ class String
2
+ def underscore
3
+ word = self.dup
4
+ word.gsub!(/::/, '/')
5
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
6
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
7
+ word.tr!("-", "_")
8
+ word.downcase!
9
+ word
10
+ end
11
+ end
data/neweden.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{neweden}
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Jason Adams}]
12
- s.date = %q{2011-09-16}
12
+ s.date = %q{2012-04-29}
13
13
  s.email = %q{jasonmadams@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -23,6 +23,8 @@ Gem::Specification.new do |s|
23
23
  "README.md",
24
24
  "Rakefile",
25
25
  "VERSION",
26
+ "init.rb",
27
+ "lib/hash_extensions.rb",
26
28
  "lib/neweden.rb",
27
29
  "lib/neweden/account.rb",
28
30
  "lib/neweden/api.rb",
@@ -33,6 +35,7 @@ Gem::Specification.new do |s|
33
35
  "lib/neweden/image.rb",
34
36
  "lib/neweden/map.rb",
35
37
  "lib/neweden/server.rb",
38
+ "lib/string_extensions.rb",
36
39
  "neweden.gemspec",
37
40
  "test/.gitignore",
38
41
  "test/config/.keep",
@@ -43,43 +46,37 @@ Gem::Specification.new do |s|
43
46
  s.homepage = %q{http://github.com/ealdent/neweden}
44
47
  s.licenses = [%q{MIT}]
45
48
  s.require_paths = [%q{lib}]
46
- s.rubygems_version = %q{1.8.6}
49
+ s.rubygems_version = %q{1.8.7}
47
50
  s.summary = %q{Ruby library for accessing Eve Online API}
48
51
 
49
52
  if s.respond_to? :specification_version then
50
53
  s.specification_version = 3
51
54
 
52
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
- s.add_runtime_dependency(%q<typhoeus>, ["= 0.2.4"])
54
- s.add_runtime_dependency(%q<nokogiri>, ["= 1.5.0"])
56
+ s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
57
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
55
58
  s.add_runtime_dependency(%q<json>, [">= 0"])
56
- s.add_runtime_dependency(%q<awesome_print>, [">= 0"])
57
- s.add_runtime_dependency(%q<active_support>, ["= 3.0.0"])
58
59
  s.add_development_dependency(%q<shoulda-context>, [">= 0"])
59
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
60
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
61
- s.add_development_dependency(%q<rcov>, [">= 0"])
60
+ s.add_development_dependency(%q<bundler>, [">= 0"])
61
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
62
+ s.add_development_dependency(%q<awesome_print>, [">= 0"])
62
63
  else
63
- s.add_dependency(%q<typhoeus>, ["= 0.2.4"])
64
- s.add_dependency(%q<nokogiri>, ["= 1.5.0"])
64
+ s.add_dependency(%q<typhoeus>, [">= 0"])
65
+ s.add_dependency(%q<nokogiri>, [">= 0"])
65
66
  s.add_dependency(%q<json>, [">= 0"])
66
- s.add_dependency(%q<awesome_print>, [">= 0"])
67
- s.add_dependency(%q<active_support>, ["= 3.0.0"])
68
67
  s.add_dependency(%q<shoulda-context>, [">= 0"])
69
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
70
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
71
- s.add_dependency(%q<rcov>, [">= 0"])
68
+ s.add_dependency(%q<bundler>, [">= 0"])
69
+ s.add_dependency(%q<jeweler>, [">= 0"])
70
+ s.add_dependency(%q<awesome_print>, [">= 0"])
72
71
  end
73
72
  else
74
- s.add_dependency(%q<typhoeus>, ["= 0.2.4"])
75
- s.add_dependency(%q<nokogiri>, ["= 1.5.0"])
73
+ s.add_dependency(%q<typhoeus>, [">= 0"])
74
+ s.add_dependency(%q<nokogiri>, [">= 0"])
76
75
  s.add_dependency(%q<json>, [">= 0"])
77
- s.add_dependency(%q<awesome_print>, [">= 0"])
78
- s.add_dependency(%q<active_support>, ["= 3.0.0"])
79
76
  s.add_dependency(%q<shoulda-context>, [">= 0"])
80
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
81
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
82
- s.add_dependency(%q<rcov>, [">= 0"])
77
+ s.add_dependency(%q<bundler>, [">= 0"])
78
+ s.add_dependency(%q<jeweler>, [">= 0"])
79
+ s.add_dependency(%q<awesome_print>, [">= 0"])
83
80
  end
84
81
  end
85
82
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neweden
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-27 00:00:00.000000000 Z
12
+ date: 2012-04-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &2165648160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
24
+ version_requirements: *2165648160
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: nokogiri
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &2165647680 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,47 +32,10 @@ dependencies:
37
32
  version: '0'
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
35
+ version_requirements: *2165647680
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: json
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: awesome_print
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :runtime
71
- 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: active_support
80
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &2165647200 !ruby/object:Gem::Requirement
81
39
  none: false
82
40
  requirements:
83
41
  - - ! '>='
@@ -85,15 +43,10 @@ dependencies:
85
43
  version: '0'
86
44
  type: :runtime
87
45
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
46
+ version_requirements: *2165647200
94
47
  - !ruby/object:Gem::Dependency
95
48
  name: shoulda-context
96
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &2165646720 !ruby/object:Gem::Requirement
97
50
  none: false
98
51
  requirements:
99
52
  - - ! '>='
@@ -101,15 +54,10 @@ dependencies:
101
54
  version: '0'
102
55
  type: :development
103
56
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
57
+ version_requirements: *2165646720
110
58
  - !ruby/object:Gem::Dependency
111
59
  name: bundler
112
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &2165646240 !ruby/object:Gem::Requirement
113
61
  none: false
114
62
  requirements:
115
63
  - - ! '>='
@@ -117,15 +65,10 @@ dependencies:
117
65
  version: '0'
118
66
  type: :development
119
67
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
68
+ version_requirements: *2165646240
126
69
  - !ruby/object:Gem::Dependency
127
70
  name: jeweler
128
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &2165645760 !ruby/object:Gem::Requirement
129
72
  none: false
130
73
  requirements:
131
74
  - - ! '>='
@@ -133,12 +76,18 @@ dependencies:
133
76
  version: '0'
134
77
  type: :development
135
78
  prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
79
+ version_requirements: *2165645760
80
+ - !ruby/object:Gem::Dependency
81
+ name: awesome_print
82
+ requirement: &2165645280 !ruby/object:Gem::Requirement
137
83
  none: false
138
84
  requirements:
139
85
  - - ! '>='
140
86
  - !ruby/object:Gem::Version
141
87
  version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *2165645280
142
91
  description:
143
92
  email: jasonmadams@gmail.com
144
93
  executables: []
@@ -155,6 +104,7 @@ files:
155
104
  - Rakefile
156
105
  - VERSION
157
106
  - init.rb
107
+ - lib/hash_extensions.rb
158
108
  - lib/neweden.rb
159
109
  - lib/neweden/account.rb
160
110
  - lib/neweden/api.rb
@@ -165,6 +115,7 @@ files:
165
115
  - lib/neweden/image.rb
166
116
  - lib/neweden/map.rb
167
117
  - lib/neweden/server.rb
118
+ - lib/string_extensions.rb
168
119
  - neweden.gemspec
169
120
  - test/.gitignore
170
121
  - test/config/.keep
@@ -186,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
137
  version: '0'
187
138
  segments:
188
139
  - 0
189
- hash: -1927723617298482446
140
+ hash: -2197534164960895585
190
141
  required_rubygems_version: !ruby/object:Gem::Requirement
191
142
  none: false
192
143
  requirements:
@@ -195,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
146
  version: '0'
196
147
  requirements: []
197
148
  rubyforge_project:
198
- rubygems_version: 1.8.23
149
+ rubygems_version: 1.8.7
199
150
  signing_key:
200
151
  specification_version: 3
201
152
  summary: Ruby library for accessing Eve Online API