Experiencing an error of undetermined nature in the bulk messaging application

I've been working on an app that can send mass texts by using a JSON file containing numbers and names. However, every time I try to test load the app in IRB, I keep encountering this error message:

NameError: undefined local variable or method `data_from_file' for main:Object
        from /home/qc/tep/Coding Stuff/Ruby/text app/main.rb:14:in `contacts_from_file'

Although I understand what the error signifies, I'm puzzled as to why it's occurring. Here is the source code snippet where the issue lies:

require 'json'

def sanatize(numbers)
    "+1" + number.gsub(/^1|\D/, "")
end

def numbers_from_file
    file = open('numbers.json').read
    JSON.parse(file)
end

def contacts_from_file
    contacts= { }
    data_from_file['feed']['entry'].each do |entry|
        name = entry['gsx$name']['$t']
        number = entry['gsx$number']['$t']
        contacts[sanatize(number)] = name
    end
    contacts
end

def contact_numbers
    contacts_from_file.keys
end

def contact_name
    contacts_from_file[number]
end

Additionally, here is a snippet of the JSON file being used:

{ 
    '1**********' => 'Big Bird'
    '1**********'} => 'Josh'
}

If anyone could guide me on why data_from_file is showing as "undefined", I would greatly appreciate it. Thank you in advance.

Answer №1

There was no prior definition of data_from_file, only an attempt to read from it in the contects_from_file function.

It seems like you intended to reference numbers_from_file instead of data_from_file.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The flag to launch Chrome maximized in Selenium WebDriver with Ruby is no longer included in desired capabilities

While working on setting my desired_capabilities for Chrome, I encountered a peculiar issue. Here is the code snippet I used: caps = { "chromeOptions" => { "prefs" => { :plugins => { :plugins_disabled => ["Chrome PDF Viewer ...

Django getJSON with jQuery causing sessionid cookie mismatch

Encountering a problem with getJSON where it is sending an incorrect value for Django's sessionid cookie. There is an API operating on port 8000. When accessing this URL: http://localhost:8000/api/accounts/banner, it returns a JSON document if there ...

Python JSON schema for extracting parameters

Are you searching for a way to parse requests to a specific URL that come in JSON format, but with varying structures? Some may have timestamps noted as timestamp attribute while others use unixtime, among other variations. The goal is to create JSON schem ...

Generating autoload commands dynamically based on filenames in Ruby

While testing a web application using Ruby, RSpec, Capybara, and Selenium, I encountered an Exception with the message "uninitialized constant ActiveAdminLoginPage" that has me stumped on how to resolve. Within spec_helper.rb, I have included the followin ...

Invalid entry detected in JSON object

I developed a code to deserialize the JSON data from this API To start off, I created a class structure: public class Self { public string href { get; set; } } // Other class definitions omitted for brevity... public class RootO ...

Using R to retrieve values from JSON lists

My knowledge in using R is limited and I need to create a script for a school project. I have a json file with nested lists, and my task is to extract values from two specific attributes. The challenge lies in the fact that these attributes are located i ...

Exploring the intricacies of ODATA SAPUI5 mockup with nested JSON structures

Having a challenge with accessing nested data from a JSON file used as mockup data in an ODATA SAPUI5 application. Below is the JSON content: [{ "testcase": { "specification": "SRS PR 28717 – Deposit in Brazilian Reais", "execution": { ...

Error: Unexpected data type encountered. Expected an array but found a string instead at line 1, column 2

I have tried multiple suggestions from similar questions but none of them have helped. How can I successfully execute this test? @Test fun isJsonCorrectPersonConvert() { val gson = GsonBuilder().create() val json = gson.toJson("[{\"Id\": ...

Discovering particular segments in strings that include specific characters or symbols, and subsequently establishing a connection to those segments

My current data storage method involves using JSON strings in a database. However, due to the presence of quotation marks in the JSONs, the database converts all quotation marks to ", making Unity unable to deserialize the JSON properly. This res ...

Using a for loop or a while loop in Powershell to iterate through a JSON object

Hey there, I'm new to Powershell and looking for some help with looping. Can someone assist me with this? Below is the JSON format from a file called Test.json: { "Pre-Production_AFM": { "allowedapps": ["app1" ...

Using JQuery Ajax to post an array

I have searched extensively for solutions, but none seem to fit my situation. Currently, I am utilizing the Jquery-Plugin DataTable with multiple tables within a form. The exact number of tables is unknown. The challenge lies in retrieving form data from ...

The error message reads: `json.decoder.JSONDecodeError: Unexpected additional data present at line 2, starting from column 1 (character

I encountered an error: (json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 5357)) when trying to parse a JSON file. Can someone explain the reason behind this error? Additionally, could you provide guidance on how to properly extract va ...

Using C# to send HttpWebRequest with a JSON POST request header

While translating a JSON API into C# Methods, I came across an issue with the JSON RPC API (POST) that states: All other methods require the result from authentication ( = sessionId), either through a path parameter ;jsessionid=644AFBF2C1B592B68C6B04938B ...

Creating a JSON object by initializing it with a string containing a regex

I need assistance with initializing a JSON object using a specific string. String myString = "{regex:/^(a-z|A-Z|0-9)*[^:*()#%`~*^&+={}| >"|\\]*$/,'value':10}"; try { JSONObject jsonObj = new JSONObject(myString); ...

python script that prints values from json data

This is the data obtained from my JSON request { "name": "North America", "region_tag": "na1", "hostname": "prod.na1.lol.riotgames.com", "services": [ { "status": "online", "incidents": [ { "active": true, ...

Is it possible to obtain the Apache server status (mod_status) output in JSON or XML format?

Exploring Apache's "mod_status" Feature: One of the functionalities provided by Apache is the "mod_status", which allows users to monitor the current status of their server. When accessed, it presents a wealth of information similar to the sample pag ...

Issues arise with the npminstall function within custom Yeoman generators

I've been researching various tutorials on how to create a custom Yeoman generator. Here's the code snippet in question: runNpm: function(){ var done = this.async(); this.npmInstall("", function(){ console.log("\nEverything Setup !!!&b ...

One REST/OData controller is throwing an HTTPException 406 while the others are unaffected

I am facing an issue with one of my Odata(4.0)/Rest controllers in my project developed using c#/.net 4.62. All controllers except for one are functioning correctly. The problematic controller consistently returns a 406 error whenever I attempt to call it. ...

Is the content of the website altered by using the request.get method? (Web scraping)

While attempting to extract data from a particular website using the requests.get method, I encountered an issue. The information retrieved from the website seems to be inconsistent and does not align with the actual data displayed on the site. For instan ...

Creating a dictionary or JSON file to store print output

Incorporating boto3 for AWS, the code snippet below showcases how to utilize it: import boto3 from trp import Document # Document s3BucketName = "bucket" documentName = "doc.png" # Amazon Textract client textract = boto3.client('textract') # ...