Last active
December 31, 2015 23:19
-
-
Save themoxman/8059265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
class RubyMeetup | |
def initialize(api_request_response) | |
# clean up the api response and set the @options_hash | |
@options_hash = prep_api_response(api_request_response) | |
# generate instance variables based on the hash keys in @options_hash | |
set_instance_vars(@options_hash) | |
# generate attr_accessor methods based on the hash keys in @options_hash | |
set_attr_accessor(@options_hash) | |
end | |
def prep_api_response(api_request_response) | |
api_request_response["results"][0] | |
end | |
def set_instance_vars(options_hash) | |
options_hash.each do |key, value| | |
instance_variable_set(:"@#{key}", value) | |
end | |
end | |
def set_attr_accessor(options_hash) | |
options_hash.each_key do |key| | |
self.class.send(:attr_accessor, key) | |
end | |
end | |
end | |
# the JSON result of making a meetup api request for Philly.rb | |
api_request_response = JSON.parse(%q/{"results":[{"lon":-75.19999694824219,"visibility":"public","organizer":{"name":"Jearvon Dharrie","member_id":85981882},"link":"http:\/\/www.meetup.com\/Phillyrb\/","state":"PA","join_mode":"open","who":"Rubyists","country":"US","city":"Philadelphia","id":7739072,"category":{"id":34,"name":"tech","shortname":"tech"},"topics":[{"id":563,"urlkey":"opensource","name":"Open Source"},{"id":1040,"urlkey":"ruby","name":"Ruby"},{"id":3833,"urlkey":"softwaredev","name":"Software Developers"},{"id":20837,"urlkey":"ruby-on-rails","name":"Ruby On Rails"},{"id":25435,"urlkey":"test-driven-development","name":"Test Driven Development"},{"id":37019,"urlkey":"beginner-web-developer","name":"Beginner Web Developer"},{"id":37917,"urlkey":"object-oriented-programming","name":"Object Oriented programming"},{"id":95825,"urlkey":"ruby-on-rails-scalability","name":"Ruby on Rails Scalability"},{"id":95826,"urlkey":"ruby-on-rails-testing","name":"Ruby on Rails Testing"},{"id":150657,"urlkey":"web-application-development","name":"web application development"},{"id":153335,"urlkey":"sinatra-ruby-framework","name":"Sinatra Ruby Framework"}],"timezone":"US\/Eastern","group_photo":{"photo_link":"http:\/\/photos4.meetupstatic.com\/photos\/event\/6\/1\/2\/8\/600_295044872.jpeg","highres_link":"http:\/\/photos2.meetupstatic.com\/photos\/event\/6\/1\/2\/8\/highres_295044872.jpeg","thumb_link":"http:\/\/photos4.meetupstatic.com\/photos\/event\/6\/1\/2\/8\/thumb_295044872.jpeg","photo_id":295044872},"created":1363982320000,"description":"<p>Philly.rb is the one and only user group in the Philadelphia area dedicated to helping Ruby enthusiasts learn, network, and socialize.<\/p>","name":"Philly.rb","rating":4.81,"urlname":"Phillyrb","lat":39.959999084472656,"members":388}],"meta":{"lon":"","count":1,"link":"http:\/\/api.meetup.com\/2\/groups.json\/","next":"","total_count":1,"url":"http:\/\/api.meetup.com\/2\/groups.json\/?key=735a652547322240967f1171647f5f&group_id=7739072&radius=25.0&order=id&desc=false&offset=0&format=json&page=200&fields=","id":"","title":"Meetup Groups v2","updated":1387465209000,"description":"\"\"","method":"Groups","lat":""}}/) | |
test = RubyMeetup.new(api_request_response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment