nineflats-api 0.0.1 → 0.0.2

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.
@@ -1,18 +1,52 @@
1
- require 'open-uri'
2
1
  require "nineflats-api/version"
2
+ require "open-uri"
3
+ require "json"
3
4
 
4
5
  module Nineflats
5
- module Api
6
- def get_data(url)
7
- data = ""
8
- begin
9
- open(url) do |f|
10
- data = JSON.parse(f.read)
6
+ module API
7
+ module Helpers
8
+ def self.get_data(url)
9
+ data = ""
10
+ begin
11
+ open(url) do |f|
12
+ data = JSON.parse(f.read)
13
+ end
14
+ rescue => e
15
+ data = "Something went wrong: #{e} --- This means either the data you requested is simply null, the data you entered was wrong, or the API call is broken."
11
16
  end
12
- rescue => e
13
- data = "Something went wrong: #{e} --- This means either the data you requested is simply null, the data you entered was wrong, or the API call is broken."
17
+ data
14
18
  end
15
- data
19
+
20
+ def self.pretty_print(data)
21
+ self.ruby_to_html(nil, data) + "</html>"
22
+ end
23
+
24
+ private
25
+
26
+ def self.ruby_to_html(html, object)
27
+ html ||= "<div class=\"object\">"
28
+ if object.is_a?(Hash)
29
+ html += "<div class=\"hash\">"
30
+ object.each do |key, value|
31
+ html += "<div class=\"key\">#{key}</div>"
32
+ html += "<div class=\"value\">"
33
+ html = ruby_to_html(html, value)
34
+ html += "</div>"
35
+ end
36
+ html += "</div>"
37
+ elsif object.is_a?(Array)
38
+ html += "<div class=\"array\">"
39
+ object.each do |element|
40
+ html += "<div class=\"element\">"
41
+ html = ruby_to_html(html, element)
42
+ html += "</div>"
43
+ end
44
+ html += "</div>"
45
+ else
46
+ html += "<div class=\"string\">#{object.to_s}</div>"
47
+ end
48
+ html
49
+ end
16
50
  end
17
51
  end
18
52
  end
@@ -1,5 +1,5 @@
1
1
  module Nineflats
2
2
  module Api
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Nineflats::Api::VERSION
8
8
  s.authors = ["Lena Herrmann"]
9
9
  s.email = ["lena@zeromail.org"]
10
- s.homepage = ""
10
+ s.homepage = "http://9flats.github.com/api_docs/index.html"
11
11
  s.summary = %q{9flats API}
12
12
  s.description = %q{Let's you use the 9flats API'}
13
13
 
@@ -17,8 +17,4 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
-
21
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
24
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nineflats-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -24,7 +24,7 @@ files:
24
24
  - lib/nineflats-api.rb
25
25
  - lib/nineflats-api/version.rb
26
26
  - nineflats-api.gemspec
27
- homepage: ''
27
+ homepage: http://9flats.github.com/api_docs/index.html
28
28
  licenses: []
29
29
  post_install_message:
30
30
  rdoc_options: []