Skip to content

Instantly share code, notes, and snippets.

View gregblake's full-sized avatar
👨‍💻

Greg Blake gregblake

👨‍💻
View GitHub Profile
FactoryBot.define do
factory :lead_photo do
document_type, name: Faker::Lorem.sentence, code: Faker::Lorem.word # If Faker doesn't work, you can also try something like Time.now.to_s, so it's always a unique string.
lead
end
end
@gregblake
gregblake / media_item_spec.rb
Created March 12, 2018 19:48
nitro-web/components/core_models/spec/models/media_item_spec.rb
require "rails_helper"
describe MediaItem, ldap: :stub do
describe "validations" do
describe "#attachment" do
context "when there is a device" do
let(:device) { build_stubbed(:mobile_device) }
let(:media_item) { build_stubbed(:media_item, device: device) }
it "should be valid" do
expect(media_item).to be_valid
@gregblake
gregblake / demo21.json
Created March 14, 2018 20:54
Frequent Contacts Now Include Rooms
{
"frequent_contacts": [
{
"frequent_contact_type": "ConnectRoom",
"frequent_contact_id": 7904,
"message_count": 32
},
{
"frequent_contact_type": "ConnectRoom",
"frequent_contact_id": 7907,
Verb Endpoint Rails Controller Action
GET /api/v3/connect/state(.:format) api/v3/connect/state#index {:format=>"json"}
GET /api/v3/connect/bookmarks(.:format) api/v3/connect/bookmarks#index {:format=>"json"}
POST /api/v3/connect/bookmarks(.:format) api/v3/connect/bookmarks#create {:format=>"json"}
DELETE /api/v3/connect/bookmarks/:id(.:format) api/v3/connect/bookmarks#destroy {:format=>"json"}
PUT|PATCH /api/v3/connect/bookmarks(.:format) api/v3/connect/bookmarks#update {:format=>"json"}
@gregblake
gregblake / connect_bookmarks.json
Created March 23, 2018 14:27
Connect Bookmarks JSON v3
{
"version": 1541,
"rooms": [
{
"id": 1699103,
"bookmarkable_type": "ConnectRoom",
"bookmarkable_id": 7148
},
{
"id": 1487573,
@gregblake
gregblake / push_notification_payload.rb
Created April 10, 2018 21:09
push_notification_payload.rb
payload = { title: "Greg Blake",
body: ConnectMessage.find(24705809).body,
data: {
sound: "NitroNotification.caf",
user_id: 31995,
badge: 1,
category: "connect-reply",
"message-type": "connect",
"as-of": Time.current.iso8601,
"nitro-environment": Rails.env,
{
"rooms": {
"1": {
"id": 1,
"name": "My Private Room",
"private": true,
"archived": false,
"broadcaster_user_ids": [],
"owner_user_ids": [],
"interested_user_ids": [],
@gregblake
gregblake / rails_console.rb
Created May 1, 2018 12:45
Rails console for bookmarks race condition
irb(main):006:0> room = ConnectRoom.last
=> #<ConnectRoom id: 9974, name: "820am", jid: nil, created_at: "2018-05-01 12:20:10", updated_at: "2018-05-01 12:20:10", created_by_id: 31995, updated_by_id: nil, private: true, archived: false, corporate_event_id: nil, short_name: nil, connect_updated_at: "2018-05-01 12:20:10", group_conversation: false>
irb(main):007:0> room.connect_bookmarks.count
=> 1
irb(main):008:0> bookmark = room.connect_bookmarks.first
=> #<ConnectBookmark id: 2296652, user_id: 31995, bookmarkable_id: 9974, bookmarkable_type: "ConnectRoom", section: "rooms", created_at: "2018-05-01 12:20:10", updated_at: "2018-05-01 12:20:10", position: 1>
irb(main):009:0> room.created_at == bookmark.created_at
=> true
irb(main):010:0> bookmark.created_at
=> Tue, 01 May 2018 08:20:10 EDT -04:00
@gregblake
gregblake / controller.rb
Created May 15, 2018 15:16
Rendering json for Project photos that may or may not be associated with a media_item
def show
project_photo = ProjectPhoto.find(params[:id])
if project_photo.media_item?
media_item = # Some method to lookup the media_item associated with the project_photo
render json: media_item.as_json
else
# You have at least 2 options here. You could:
# 1) refactor the project_photo Boxer representation into a similar as_json method, or
# 2) Modify the existing project_photo Boxer representation, and render the json using Boxer.
end
@gregblake
gregblake / mdm.html
Last active May 29, 2018 21:25
MDM: Connect app for Android
<div class="media">
<div class="media-left">
<a href="javascript:void(0)">
<img class="media-object img-rounded" src="/assets/connect-logo.png" alt="Connect logo" width="72" height="72">
</a>
</div>
<div class="media-body">
<h2 class="media-heading">Connect for Android</h2>
<p>Version 1</p>
</div>