Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meetup organization #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class OrganizationsController < ApplicationController
before_action :set_organization, only: [:show, :edit, :update, :destroy]

# GET /organizations
# GET /organizations.json
def index
@organizations = Organization.all
end

# GET /organizations/1
# GET /organizations/1.json
def show
end

# GET /organizations/new
def new
@organization = Organization.new
end

# GET /organizations/1/edit
def edit
end

# POST /organizations
# POST /organizations.json
def create
@organization = Organization.new(organization_params)

respond_to do |format|
if @organization.save
format.html { redirect_to @organization, notice: 'Organization was successfully created.' }
format.json { render action: 'show', status: :created, location: @organization }
else
format.html { render action: 'new' }
format.json { render json: @organization.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /organizations/1
# PATCH/PUT /organizations/1.json
def update
respond_to do |format|
if @organization.update(organization_params)
format.html { redirect_to @organization, notice: 'Organization was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @organization.errors, status: :unprocessable_entity }
end
end
end

# DELETE /organizations/1
# DELETE /organizations/1.json
def destroy
@organization.destroy
respond_to do |format|
format.html { redirect_to organizations_url }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_organization
@organization = Organization.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def organization_params
params.require(:organization).permit(:url, :name, :about)
end
end
2 changes: 2 additions & 0 deletions app/helpers/organizations_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module OrganizationsHelper
end
19 changes: 19 additions & 0 deletions app/models/meetup_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class MeetupApi
BASE_URL = 'https://api.meetup.com'
AUTH = "sign=true&key=#{ENV['MEETUP_KEY']}"

def self.is_meetup_url(url)
url =~ /meetup.com/
end

def self.group(url)
group_name = URI.parse(url).path.split('/').second
url = "#{BASE_URL}/#{group_name}?#{AUTH}"
response = HTTParty.get(url)

# watch out for the rate limit
#p response.headers

response.parsed_response
end
end
12 changes: 12 additions & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Organization < ActiveRecord::Base
before_create :check_url

def check_url
if MeetupApi.is_meetup_url(url)
group = MeetupApi.group(url)
self.name = group['name']
self.about = group['description']
self.meetup_id = group['id']
end
end
end
34 changes: 34 additions & 0 deletions app/views/organizations/_form.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
= form_for @organization, :html => {class:'form'} do |f|
- if @organization.errors.any?
#error_explanation
h2 = "#{pluralize(@organization.errors.count, "error")} prohibited this organization from being saved:"
ul
- @organization.errors.full_messages.each do |message|
li = message

// URL
.icon-group
.icon
.icon-content
.form-group
= f.text_field :url, class:'form-control', placeholder:'Organization URL', tabindex: autoTabIndex

// Name
.icon-group
.icon
.icon-content
.form-group
= f.text_field :name, class:'form-control', placeholder:'Organization Name', tabindex: autoTabIndex

// About
.icon-group
.icon
i.glyphicon.glyphicon-info-sign
.icon-content
.form-group
= f.text_area :about, class:'form-control', placeholder:'A description of the organization', rows: 5, tabindex: autoTabIndex

.icon-group
.icon
.icon-content
= f.submit
8 changes: 8 additions & 0 deletions app/views/organizations/edit.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
h1 Editing organization

== render 'form'

= link_to 'Show', @organization
'|
= link_to 'Back', organizations_path

19 changes: 19 additions & 0 deletions app/views/organizations/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
h1 Listing organizations

table
thead
tr
th
th
th

tbody
- @organizations.each do |organization|
tr
td = link_to 'Show', organization
td = link_to 'Edit', edit_organization_path(organization)
td = link_to 'Destroy', organization, data: {:confirm => 'Are you sure?'}, :method => :delete

br

= link_to 'New Organization', new_organization_path
4 changes: 4 additions & 0 deletions app/views/organizations/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
json.array!(@organizations) do |organization|
json.extract! organization, :id
json.url organization_url(organization, format: :json)
end
6 changes: 6 additions & 0 deletions app/views/organizations/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.icon-container
.icon-group
.icon
.icon-content
h3 New organization
== render 'form'
17 changes: 17 additions & 0 deletions app/views/organizations/show.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
p#notice = notice

h2 Name
.div
= link_to @organization.name, @organization.url

h2 Description
.div
= simple_format(@organization.about)

h2 URL
.div
= link_to @organization.url, @organization.url

= link_to 'Edit', edit_organization_path(@organization)
'|
= link_to 'Back', organizations_path
1 change: 1 addition & 0 deletions app/views/organizations/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.extract! @organization, :id, :created_at, :updated_at
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
resources :events
get 'calendar', to: 'events#calendar'

resources :organizations


# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
Expand Down
7 changes: 1 addition & 6 deletions db/migrate/20150323044944_remove_location_from_events.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
class RemoveLocationFromEvents < ActiveRecord::Migration
def change
def up
remove_column :events, :location
end
def down
add_column :events, :location, :string
end
remove_column :events, :location
end
end
12 changes: 12 additions & 0 deletions db/migrate/20150822155300_create_organizations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateOrganizations < ActiveRecord::Migration
def change
create_table :organizations do |t|
t.string :name
t.text :about
t.string :url
t.string :meetup_id

t.timestamps null: false
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20150823235104_add_organization_to_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddOrganizationToEvents < ActiveRecord::Migration
def change
add_reference :events, :organization, index: true, foreign_key: true
end
end
31 changes: 21 additions & 10 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150323211739) do
ActiveRecord::Schema.define(version: 20150823235104) do

create_table "events", force: :cascade do |t|
t.string "title", limit: 255
t.string "title"
t.datetime "start"
t.datetime "finish"
t.string "location", limit: 255
t.string "ticketurl", limit: 255
t.string "ticketurl"
t.datetime "created_at"
t.datetime "updated_at"
t.text "description"
t.integer "organization_id"
end

add_index "events", ["organization_id"], name: "index_events_on_organization_id"

create_table "location_events", force: :cascade do |t|
t.integer "location_id"
t.integer "event_id"
Expand All @@ -48,6 +50,15 @@
t.string "long_address"
end

create_table "organizations", force: :cascade do |t|
t.string "name"
t.text "about"
t.string "url"
t.string "meetup_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "user_events", force: :cascade do |t|
t.integer "user_id", null: false
t.integer "event_id"
Expand All @@ -59,16 +70,16 @@
add_index "user_events", ["user_id"], name: "index_user_events_on_user_id"

create_table "users", force: :cascade do |t|
t.string "email", limit: 255, default: "", null: false
t.string "encrypted_password", limit: 255, default: "", null: false
t.string "reset_password_token", limit: 255
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip", limit: 255
t.string "last_sign_in_ip", limit: 255
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
end
Expand Down
Loading