Git Product home page Git Product logo

pilha's Introduction

Pilha

A object oriented wrapper for the StackExchange/StackOverflow API

Why such a strange name?

‘Pilha’ (pronounced peeleeah) means ‘stack’ in portuguese.

Instalation

gem install pilha

Example

Pilha aims to provide a ActiveRecord like interface for querying the StackExchange API.

include StackExchange::StackOverflow
StackExchange::StackOverflow::Client.config do |options|
  options.api_key = 'your_key' #optional
end

Badge.all # returns all badges
User.find_by_badge_id(2) # returns all users awarded by the badge identified with 'id'

As all response objects returned by Pilha are instances of OpenStruct, so you need to call the ‘api_methods’ on a desired class to see which methods of the OpenStruct were added by the gem.

Question.api_methods

# => [:@struct, :question_id, :tags, :creation_date, :last_activity_date, :up_vote_count,
    :down_vote_count, :view_count, :score, :community_owned, :title, :body, :answers,
    :answer_count, :accepted_answer_id, :favorite_count, :question_timeline_url,
    :question_comments_url, :question_answers_url, :owner]

Contributors

Michael Barton (http://github.com/michaelbarton)
Thomas McDonald (http://github.com/conceptcoding)

License

(The MIT License)

Copyright © 2010-2011 Dalto Curvelano Junior

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pilha's People

Contributors

dlt avatar michaelbarton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pilha's Issues

The :options hash seems to be b0rked

The options in the query() don't seem to work....when I pass the options as:

@questions = Question.find_by_user_id(params[:id], :body => true, :page => 2, :pagesize => 10)

It still returns something like:

#<OpenStruct total=254, page=1, pagesize=30, questions=[#<Sta

The more I dig into it, the more it seems that the options are not being passed as parameters in the URL.

When I do this:

    logger.debug(@questions)

This is the result of my params:

    Started GET "/?id=91970" for 127.0.0.1 at 2011-12-05 19:04:26 -0500
    Processing by HomeController#index as HTML
    Parameters: {"id"=>"91970"}

No support for other Stackexchange sites

There is no support for any of the other Stackexchange network sites.

How should this be added? Replicate the StackOverflow parts, just re-name it to the appropriate SE site name, or do something else? I'm open to working on this.

Getting undefined method NilClass

Hi All,
I am using your pilha to talk with StackOverfow site in my app I am getting the following exception. Kindly help to solve that issue.

rake aborted!
undefined method request' for nil:NilClass c:/ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.10/lib/active_support/whiny_ nil.rb:52:inmethod_missing'
c:/ruby187/lib/ruby/gems/1.8/gems/pilha-0.2.1/lib/pilha/stack_overflow/base.rb:1
7:in request' c:/ruby187/lib/ruby/gems/1.8/gems/pilha-0.2.1/lib/pilha/stack_overflow/question. rb:15:inall'

No search method

There is no search method but /search exist in the original api.

The struct method 'accept_rate' doesn't work - for User object

ruby-1.9.2-p0 > u
=> #<StackExchange::StackOverflow::User:0x00000100e63358 @struct=#<OpenStruct user_id=91970, user_type="registered", creation_date=1239946368, display_name="marcamillion", reputation=1415, email_hash="64aa7d1e0eb006175565adb0a47a4452", age=28, last_access_date=1322958915, website_url="http://marcgayle.com", location="Jamaica", about_me="<p>Geek that loves business &amp; tech.</p>\n", question_count=253, answer_count=30, view_count=315, up_vote_count=316, down_vote_count=4, accept_rate=87, association_id="530c4d1d-a273-401d-9df9-31c08e230fd0", user_questions_url="/users/91970/questions", user_answers_url="/users/91970/answers", user_favorites_url="/users/91970/favorites", user_tags_url="/users/91970/tags", user_badges_url="/users/91970/badges", user_timeline_url="/users/91970/timeline", user_mentioned_url="/users/91970/mentioned", user_comments_url="/users/91970/comments", user_reputation_url="/users/91970/reputation", badge_counts={"gold"=>0, "silver"=>9, "bronze"=>28}>> 
 ruby-1.9.2-p0 > u.accept_rate
 NoMethodError: undefined method `accept_rate' for #<StackExchange::StackOverflow::User:0x00000100e63358>
from (irb):33

How do I use Ruby or Rails methods on returned collections?

how I access each of the elements?

For instance:

@questions = Question.find_by_user_id(params[:id], :body => true, :pagesize => 10)

When I do:

@questions.first

It returns blank.

Am I missing something?

I also tried sorting the results, but it is giving me a problem.

I did this in my controller:

@questions = Question.find_by_user_id(params[:id]).order("created_at ASC")

And it produced this error:

undefined method `order' for #<OpenStruct total=254, page=1, pagesize=30, questions=[#<StackExchange::StackOv

Basically, a lot of the regular Rails stuff that I am trying, are giving me problems.

What am I doing wrong? Or is all of this part of the OpenStruct issue?

Edit 1:

Btw, the same applies to other regular Rails functions, e.g.:

@questions = Question.find_by_user_id(params[:id]).limit(5)

Throws the error:

undefined method `limit' for #<OpenStruct total=254, page=1, pagesize=30, questions=[#<StackExc

Getting undefined method NilClass

Hi All,
I am using using the following pilha code ,

StackExchange::StackOverflow.config do |options|
options.api_key = 'My Key'
end
questions = StackExchange::StackOverflow::Question.all(:tagged => 'math', :body => true)

I am getting the following exception.

rake aborted!
undefined method request' for nil:NilClass
c:/ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.10/lib/active_support/whiny_
nil.rb:52:inmethod_missing'
c:/ruby187/lib/ruby/gems/1.8/gems/pilha-0.2.1/lib/pilha/stack_overflow/base.rb:1
7:in request'
c:/ruby187/lib/ruby/gems/1.8/gems/pilha-0.2.1/lib/pilha/stack_overflow/question.
rb:15:inall'

Kindly help me out to resolve the issue.

I am executing it in windows machine.

Thanks
Malligarjunan S.

Ruby's first and count methods don't work on returned collection

So say I do:

q = Question.find_by_user_id(91970)

It returns a long list of stuff,

but if I do:

ruby-1.9.2-p0 > q.count
=> nil
ruby-1.9.2-p0 > q.first
=> nil

At first I thought it was maybe a Ruby 1.9.2 issue, but then I tried it in 1.8.7 and am getting the same issue.

How do I iterate through a collection and get Ruby's array methods to work?

The irony is, that you seem to have used .first in the library of Pilha, so not sure what's happening here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.