bbc_api 0.1.0

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.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'rake'
5
+ gem 'webmock'
@@ -0,0 +1,53 @@
1
+ <html>
2
+ <head>
3
+ <title>BBC API INTEGRATION</title>
4
+ </head>
5
+ <body>
6
+ <h1>BBC WORLD NEWS API Integration</h1>
7
+ <p>
8
+ <a href="https://travis-ci.org/rajcybage/bbc_api"><img src="https://travis-ci.org/rajcybage/bbc_api.png?branch=master" alt="Build Status" /></a>
9
+ </p>
10
+ <div>
11
+ <p>
12
+ Integrate BBC world NEWS API to get all topic wise stories,headlines,world news. You can install it as a desktop application as well as Rails Application
13
+ </p>
14
+ </div>
15
+ <div>
16
+ <h1>System Requirements</h1>
17
+ <p>
18
+ <code>Ruby >= 1.9.3 or jruby >=1.7.x</code><br/>
19
+ <code>rails >= 3.0.x</code>
20
+ </p>
21
+ </div>
22
+
23
+ <div>
24
+ <h1> Installation </h1>
25
+ <p>
26
+ In Gemfile
27
+ </p>
28
+ <p>
29
+ <code>gem "bbc_api", git: "https://github.com/rajcybage/bbc_api"</code><br/>
30
+ <span>OR</span><br/>
31
+ <code>gem "bbc_api", "0.1.0" </code>
32
+ </p>
33
+ </div>
34
+
35
+ <div>
36
+ <h1> USAGE</h1>
37
+ <p>
38
+ <code>require 'bbc_api'</code><br/>
39
+ <code>bbc = BBC::Api.new</code><br/>
40
+ <h2>Get The topics</h2><br/>
41
+ <code>bbc.topics</code><br/>
42
+ <p><b>It will return all the topics like HEAlines,Technology,entertainment,world,uk...etc</b></p>
43
+ <code>bbc.topics.first.stories</code>
44
+ <p><b>It will return the stories or the news of the corresponding topic..</b></p>
45
+ <h2>Now You can access This Attributes of the Story</h2>
46
+ <p><b><code>bbc.topics.first.stories.title</code><span>the title of that newz</span><br/>
47
+ <code>bbc.topics.first.stories.link</code><span>the link of that newz</span><br/>
48
+ <code>bbc.topics.first.stories.image</code><span>the image of that newz</span><br/>
49
+ <code>bbc.topics.first.stories.description</code><span>the description of that newz</span></b>
50
+ </p>
51
+ </p>
52
+ </body>
53
+ </html>
@@ -0,0 +1,32 @@
1
+ require 'json'
2
+ require 'socket'
3
+ require_relative 'uri.rb'
4
+ require_relative 'topic.rb'
5
+
6
+ module BBC
7
+ class Api
8
+ attr_accessor :topics
9
+ attr_reader :response
10
+
11
+ def initialize
12
+ @response = JSON.parse(URI::Uri.new(URI(BBC.api_url+"/topics")).response.body)["topics"]
13
+ end
14
+
15
+ def topics
16
+ @topics = []
17
+ @response.each do |hash|
18
+ @topics << Topic.new(:id => hash["id"], :title => hash["title"])
19
+ end
20
+ @topics
21
+ end
22
+
23
+ def build_topics_hash
24
+ @topics.each_with_index.inject({}){|result, (element,i)| result.merge Hash[i.succ, element]}
25
+ end
26
+ end
27
+
28
+ def BBC.api_url
29
+ url = "http://api.bbcnews.appengine.co.uk"
30
+ end
31
+
32
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'base.rb'
2
+ require_relative 'uri.rb'
3
+ require_relative 'story.rb'
4
+
5
+ class Story
6
+
7
+ attr_accessor :story
8
+
9
+ def initialize(story)
10
+ @story = story
11
+ end
12
+
13
+ def title
14
+ @story["title"]
15
+ end
16
+
17
+ def description
18
+ @story["description"]
19
+ end
20
+
21
+ def link
22
+ @story["link"]
23
+ end
24
+
25
+ def image
26
+ @story["thumbnail"]
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'base.rb'
2
+ require_relative 'uri.rb'
3
+ require_relative 'story.rb'
4
+
5
+ class Topic
6
+ attr_accessor :id, :title, :stories
7
+
8
+ def initialize(id = nil,title = nil)
9
+ @id = id[:id]
10
+ @title = title
11
+ end
12
+
13
+ def stories
14
+ @stories = []
15
+ response = JSON.parse(URI::Uri.new(URI(BBC.api_url+"/stories/#{@id}")).response.body)["stories"].each do |story|
16
+ @stories << Story.new(story)
17
+ end
18
+ @stories
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ require 'net/http'
2
+ require 'openssl'
3
+ module URI
4
+ class Uri
5
+ attr_reader :uri
6
+ attr_accessor :response
7
+
8
+ def initialize(uri)
9
+ @uri = uri
10
+ http = Net::HTTP.new(@uri.host, @uri.port)
11
+ http.use_ssl = false
12
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
13
+ @response = http.get(@uri.request_uri)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module BbcApi
2
+ Version = "0.1.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'bbc/version.rb'
2
+ require_relative 'bbc/uri.rb'
3
+ require_relative 'bbc/base.rb'
@@ -0,0 +1,19 @@
1
+ require_relative '../lib/bbc/base.rb'
2
+ require_relative '../lib/bbc/uri.rb'
3
+ require_relative '../lib/bbc/topic.rb'
4
+ require_relative 'spec_helper.rb'
5
+
6
+ describe "Initialize" do
7
+ before(:all) do
8
+ @response = JSON.parse(URI::Uri.new(URI(BBC.api_url+"/topics")).response.body)["topics"]
9
+ end
10
+
11
+ it "should connect bbc api" do
12
+ stub_request(:get, "http://api.bbcnews.appengine.co.uk").to_return(:body => "")
13
+ end
14
+
15
+ it "should return an array of json" do
16
+ @response.should_not be_nil
17
+ @response.should be_a_kind_of(Array)
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'rspec'
8
+ require 'rspec/expectations'
9
+ require 'rspec/mocks'
10
+ require 'rspec/core'
11
+ require 'webmock/rspec'
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+ WebMock.allow_net_connect!(:net_http_connect_on_start => true)
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bbc_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rajarshi Das
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: rdasarminus@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - Gemfile
22
+ - lib/bbc_api.rb
23
+ - lib/bbc/base.rb
24
+ - lib/bbc/story.rb
25
+ - lib/bbc/topic.rb
26
+ - lib/bbc/uri.rb
27
+ - lib/bbc/version.rb
28
+ - spec/base_spec.rb
29
+ - spec/spec_helper.rb
30
+ homepage: https://github.com/rajcybage/bbc_api
31
+ licenses:
32
+ - MIT
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ none: false
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ none: false
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.24
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Integrate BBC world NEWZ Api to get all topic wise stories,headlines,world newz
55
+ test_files: []
56
+ has_rdoc: