kraai 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d4f6fe9522b4bafab09ffe4470dc3d4ee5ebabd
4
+ data.tar.gz: 82419b772010cbffd0b08c476661b316094bb507
5
+ SHA512:
6
+ metadata.gz: 0de680f357694b1da06d4ee265aa9fd54c6f13b548b4b932e6a2cafedaf42e06a7a0682dc79d616aee54c0a4b579d515210a53b6581655914dd8c92e98ade962
7
+ data.tar.gz: ae31780c9070fbda01f63c7182b2c0c640e08edd17c25e20a2967594e33d40fc893af3865ef9205bc554978d54f2009a6ccc9b6017491a37910db9e511126517
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kraai.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Andre Mouton
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Kraai
2
+ Ruby wrapper for StackExchange Api.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'kraai'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install kraai
17
+
18
+ ## Usage
19
+
20
+ Create a new kraai object by calling:
21
+
22
+ Kraai::StackExchange.new
23
+
24
+ This will create the object with several default values that can be overwritten at call time, eg:
25
+
26
+ site = "stackoverflow", page = 1, sort = "activity", order = "desc"
27
+
28
+ You can now call several methods on this now object:
29
+
30
+ .user_questions(user)
31
+
32
+ Returns 30 questions for given user.
33
+
34
+ .user_answers(user)
35
+
36
+ Returns 30 answers for given user.
37
+
38
+ .unanswered(tagged)
39
+ Returns 30 questions with given tag with no accepted answer
40
+
41
+ .noanswers(tagged)
42
+ Returns 30 questions with given tag with no answers.
43
+
44
+ ## Example
45
+
46
+ response = Kraai::StackExchange.new
47
+ response.site = "stackoverflow"
48
+ response.unanswered("ruby")
49
+ Returns 30 unanswered questions tagged ruby
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( http://github.com/<my-github-username>/kraai/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
data/kraai.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kraai/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kraai"
8
+ spec.version = Kraai::VERSION
9
+ spec.authors = ["Andre Mouton"]
10
+ spec.email = ["andre@amtek.co.za"]
11
+ spec.summary = %q{Api wrapper for stackoverflow.}
12
+ spec.description = %q{Api wrapper for stackoverflow.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "vcr"
25
+ spec.add_development_dependency "webmock"
26
+ spec.add_dependency "httparty"
27
+
28
+ end
@@ -0,0 +1,3 @@
1
+ module Kraai
2
+ VERSION = "0.0.1"
3
+ end
data/lib/kraai.rb ADDED
@@ -0,0 +1,63 @@
1
+ require "kraai/version"
2
+ require "httparty"
3
+ module Kraai
4
+
5
+ class StackExchange
6
+ include HTTParty
7
+ attr_accessor :site, :page, :order, :sort, :tagged, :user
8
+ # Api Example
9
+ # HTTParty.get('https://api.stackexchange.com/2.1/users/1327379/answers?order=desc&sort=activity&site=stackoverflow')
10
+
11
+ base_uri 'api.stackexchange.com/2.2'
12
+
13
+ def initialize(site="stackoverflow", page=1, sort="activity", order="desc")
14
+ @options = { :query => {:site => site, :page => page, :sort => sort, :order => order} }
15
+ @site = site
16
+ @page = page
17
+ @sort = sort
18
+ @order = order
19
+
20
+ end
21
+
22
+ def questions
23
+ self.class.get("/questions", @options)
24
+ end
25
+
26
+ def user_questions(user)
27
+ @user = user
28
+ self.class.get("/users/#{user}/questions", @options)
29
+ end
30
+
31
+ def user_answers(user)
32
+ @user = user
33
+ self.class.get("/users/#{user}/answers", @options)
34
+ end
35
+
36
+
37
+ def unanswered(tagged)
38
+ self.tagged = tagged
39
+ @options[:query].merge! :tagged => tagged
40
+ self.class.get("/questions/unanswered", @options)
41
+ end
42
+
43
+ def noanswers(tagged)
44
+ @tagged = tagged
45
+ (@options[:query].merge! :tagged => tagged) if tagged
46
+ self.class.get("/questions/no-answers", @options)
47
+ end
48
+
49
+ def users
50
+ self.class.get("/users", @options)
51
+ end
52
+
53
+ def self.sites
54
+ HTTParty.get('https://api.stackexchange.com/2.2/sites')
55
+ end
56
+
57
+
58
+ end
59
+
60
+
61
+
62
+
63
+ end
@@ -0,0 +1,28 @@
1
+ require 'kraai'
2
+ require 'webmock/rspec'
3
+ require 'vcr'
4
+ WebMock.disable_net_connect!(allow_localhost: true)
5
+ # This file was generated by the `rspec --init` command. Conventionally, all
6
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
7
+ # Require this file using `require "spec_helper"` to ensure that it is only
8
+ # loaded once.
9
+ #
10
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
21
+ end
22
+
23
+ VCR.configure do |c|
24
+ #the directory where your cassettes will be saved
25
+ c.cassette_library_dir = 'spec/vcr'
26
+ # your HTTP request service. You can also use fakeweb, webmock, and more
27
+ c.hook_into :webmock
28
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+ require 'vcr'
3
+ # require_relative '../lib/kraai'
4
+
5
+ describe Kraai::StackExchange do
6
+
7
+ let(:response) { Kraai::StackExchange.new }
8
+
9
+ describe "default options get set on .new" do
10
+
11
+ it "should set site" do
12
+ response.site.should eq('stackoverflow')
13
+ end
14
+
15
+ it "should set page" do
16
+ response.page.should eq(1)
17
+ end
18
+
19
+ it "should set order" do
20
+ response.order.should eq("desc")
21
+ end
22
+
23
+ it "should set sort" do
24
+ response.sort.should eq("activity")
25
+ end
26
+
27
+ end
28
+
29
+ describe ".unanswered" do
30
+
31
+ it "should respond ok" do
32
+ VCR.use_cassette 'stackexchange/unanswered' do
33
+ response.unanswered("ruby").response.code.should eq('200')
34
+ end
35
+
36
+ end
37
+
38
+ it "should set tag" do
39
+ VCR.use_cassette 'stackexchange/unanswered' do
40
+ response.unanswered("ruby")
41
+ response.tagged.should eq("ruby")
42
+ end
43
+
44
+ end
45
+ end
46
+
47
+ describe ".noanswers" do
48
+
49
+ it "should respond ok" do
50
+ VCR.use_cassette 'stackexchange/noanswers' do
51
+ response.noanswers("ruby").response.code.should eq('200')
52
+ end
53
+
54
+ end
55
+
56
+ it "should set tag" do
57
+ VCR.use_cassette 'stackexchange/noanswers' do
58
+ response.noanswers("ruby")
59
+ response.tagged.should eq("ruby")
60
+ end
61
+
62
+ end
63
+ end
64
+
65
+ describe ".user_questions" do
66
+
67
+ it "should respond ok" do
68
+ VCR.use_cassette 'stackexchange/user_questions' do
69
+ response.user_questions("1397997").response.code.should eq('200')
70
+ end
71
+
72
+ end
73
+
74
+ it "should set user" do
75
+ VCR.use_cassette 'stackexchange/user_questions' do
76
+ response.user_questions("1397997")
77
+ response.user.should eq("1397997")
78
+ end
79
+
80
+ end
81
+ end
82
+
83
+ describe ".user_answers" do
84
+
85
+ it "should respond ok" do
86
+ VCR.use_cassette 'stackexchange/user_answers' do
87
+ response.user_answers("1397997").response.code.should eq('200')
88
+ end
89
+
90
+ end
91
+
92
+ it "should set user" do
93
+ VCR.use_cassette 'stackexchange/user_answers' do
94
+ response.user_answers("1397997")
95
+ response.user.should eq("1397997")
96
+ end
97
+
98
+ end
99
+ end
100
+ end